TypeError: stack[0] is undefined

Before anything, I’ve gone through these posts.


and

I could not find the solution for this problem on either thread.

I was running a Quicktest, when this showed up.

HeistModule,goto VelvetCutsB,9574F,10106F,2505F
HeistModule,goto VelvetCutsB,9574F,10106F,2506F
HeistModule,goto VelvetCutsB,9574F,10106F,2508F
HeistModule,goto VelvetCutsB,9574F,10106F,10146F
QUICKTEST FAILED
TypeError: stack[0] is undefined

I then went and ran a Randomtest, and this showed up.

You're at the loot already, if nothing goes wrong, you should be out of there before cops arrive.

HeistModule *choice 10160#2 (line 10164) #"Roger that"

"Good luck. I'll tell you if anything changes.. Mouse out"

RANDOMTEST FAILED: TypeError: stack[0] is undefined

At first, I thought it was because I had a *return command going back from a *goto, but when I went through the codes, everything seemed perfectly fine.

You're at the loot already, if nothing goes wrong, you should be out of there before cops arrive.

*fake_choice
	#"Thanks for the update"
		*set RelMouse +2
		"You're welcome!" ${Mhe} says cheerfully.
	#"Roger that"
	#Say nothing
"Good luck. I'll tell you if anything changes.. Mouse out"

*if HeistNum = 1
	Sariel also decides to chime in.
	*if S_token = 1
		"Hey, hey. How's it going in there?" You hear him mumbling through the earpiece. You also hear a faint sound of chewing in the background. 
		
		"Everything alright?" He asks, he sounds as if he has something in his mouth.
	*if S_token = 2
		"Hello? Hey, is everything alright in there?" You hear her through the earpiece. You also hear a faint sound of music in the background. 
	*fake_choice
		*if (S_token = 1) #".. Are you eating something?"
			*set RelCharlie +3
			"Yeah, I got hungry and there was a Mike Donald's cheeseburger in the glove box.."
			
			*if U_Token = 1
				"Hey! That's MY cheeseburger!!" Uriel shouts into her radio.
				
				"Oh shit.. um.."
				
				"You better not be halfway through, or I'll shove my crowbar down your throat!" She angrily scolds her brother.
				
				"I.. um.. may have just finished it.."
				
				"... You owe me a cheeseburger!"
				
				"Okay! sorry.." His voice trails off
			
			"Is there anyone there? You're supposed to be lookout" Uriel says.
			
			"Nah, no one's here.. just me and the ${heistvehicle}.. There was a fly a few minutes ago but I got it out.."
			
			"Alright just keep an eye out. Tell me if you see anything" You say to him.
			
			"Roger that, governor!"
		*if (S_token = 2) #".. Are you listening to the radio?"
			*set RelCarly +3
			"Yes, I mean, what else am I supposed to do? I'm just waiting on you three"
			
			"Is there anyone there? You're supposed to be lookout"
			
			"No, no. No one's here. Just me and the ${heistvehicle}. There [i]was[/i] a squirrel in the parking lot a few moments ago, but I think something scared it away.."
			
			"Alright just keep an eye out. Tell me if you see anything" You say to her.
			
			"Yes sir! My eyes are open"
		#"We're good, how are you?"
			*set RelCharlie +2
			*set RelCarly +2
			"Sleepy, but doing well. Thanks for asking. How's the robbery going?"
			
			"We're at the loot, should be done in a few.."
			
			"Oh, great to hear! I'll be in the ${heistvehicle} if you need me.."
		#"We're at the loot, should be done in a few.."
			"Oh, great to hear! I'll be in the ${heistvehicle} if you need me.."
			*set RelCharlie +1
			*set RelCarly +1
		#"Shut up and just wait for us"
			*set RelCharlie -4
			*set RelCarly -4
			*if S_token = 1
				"Sorry, jeez. I was just starting a conversation.." He stops talking.
			*if S_token = 2
				"Oh.. uh. Sorry.." She stops talking.
*return

And so, I decided to look through the .js files, and I found this in the scene.js file:

Scene.prototype.create = function create(line) {
    var result = /^(\w*)(.*)/.exec(line);
    if (!result) throw new Error(this.lineMsg()+"Invalid create instruction, no variable specified: " + line);
    var variable = result[1];
    this.validateVariable(variable);
    variable = variable.toLowerCase();
    var expr = result[2];
    var stack = this.tokenizeExpr(expr);
    if (stack.length === 0) throw new Error(this.lineMsg()+"Invalid create instruction, no value specified: " + line);
    var self = this;
    function complexError() {
      throw new Error(self.lineMsg()+"Invalid create instruction, value must be a a number, true/false, or a quoted string: " + line);
    }
    if (stack.length > 1) complexError();
    var token = stack[0];
    if (!/STRING|NUMBER|VAR/.test(token.name)) complexError();
    if ("VAR" == token.name && !/^true|false$/i.test(token.value)) complexError();
    if ("STRING" == token.name && /(\$|@)!?!?{/.test(token.value)) throw new Error(this.lineMsg() + "Invalid create instruction, value must be a simple string without ${} or @{}: " + line);
    var value = this.evaluateExpr(stack);
    this.stats[variable] = value;
    if (this.nav) this.nav.startingStats[variable] = value;
};

I have to be honest, I have no clue how to work Javascript, so I don’t know if it’s related or not…

Either way, thank you in advance for even taking the time to read this…

2 Likes

Whoaw. You can nest nothing under an option?

I mean, this one :point_down:t4:

*fake_choice
	#"Thanks for the update"
		*set RelMouse +2
		"You're welcome!" ${Mhe} says cheerfully.
	#"Roger that"
	#Say nothing
"Good luck. I'll tell you if anything changes.. Mouse out"

Even when I manually test it, choicescript won’t let me to pass the #"Roger that" option.

I thought *fake_choice commands doesn’t need anything to go through. Unlike *choice commands which needs something nesting in it with a *goto or *goto_scene command at the end.

Oh, I see.

Yes, that’s right. I no longer use *fake_choice command, you know. But I remember that *fake_choice can do that, somehow. :thinking:

But there you go. I bet the error is located on that particular line :point_up:t4:

1 Like

I thought about that, so I blocked the whole thing with *comment… but it still happens.

"Raphael.." Mouse calls out for you. "Mouse here. Remember that call that went out? Yeah.. um, there's a couple cop cars coming to your direction. You might want to hurry.. ETA 3 minutes until they arrive"

You're at the loot already, if nothing goes wrong, you should be out of there before cops arrive.

RANDOMTEST FAILED: TypeError: stack[0] is undefined

Here’s the whole label.

*label OPPalarmcheck2
*set countslot2 0
"Raphael.." Mouse calls out for you.
*if HeistCondition = 1
	"Mouse here. Good news, no alarms have gone off yet, and looking through everything, I don't think anyone knows you're there... Oh, and Gabriel says 'good job'"
*if HeistCondition = 2
	"Mouse here. Good news, no alarms have gone off yet. You're still in the clear. Make sure you took care of all of the guards. I'll let you know if anything happens"
*if HeistCondition = 3
	*if HeistCountdownStart = true
		*set countslot2 1
		"Mouse here. Remember that call that went out? Yeah.. um, there's a couple cop cars coming to your direction. You might want to hurry.. ETA ${HeistCountdown} minutes until they arrive"
	*if HeistCountdownStart = false
		*set HeistCountdownStart true
		"This is Mouse. I just received a 911 call from the outside. Either something tripped another alarm, or someone must've heard something.. Be advised, they [i]DO[/i] know you're there, and you have ${HeistCountdown} minutes to get the job done.."

You're at the loot already, if nothing goes wrong, you should be out of there before cops arrive.

*comment *fake_choice
	*comment #"Thanks for the update"
		*comment *set RelMouse +2
		*comment "You're welcome!" ${Mhe} says cheerfully.
	*comment #"Roger that"
	*comment #Say nothing
*comment "Good luck. I'll tell you if anything changes.. Mouse out"

*comment *if HeistNum = 1
	*comment Sariel also decides to chime in.
	*comment *if S_token = 1
		*comment "Hey, hey. How's it going in there?" You hear him mumbling through the earpiece. You also hear a faint sound of chewing in the background. 
		
		*comment "Everything alright?" He asks, he sounds as if he has something in his mouth.
	*comment *if S_token = 2
		*comment "Hello? Hey, is everything alright in there?" You hear her through the earpiece. You also hear a faint sound of music in the background. 
	*comment *choice
		*comment *if (S_token = 1) #".. Are you eating something?"
			*comment *set RelCharlie +3
			*comment "Yeah, I got hungry and there was a Mike Donald's cheeseburger in the glove box.."
			
			*comment *if U_Token = 1
				*comment "Hey! That's MY cheeseburger!!" Uriel shouts into her radio.
				
				*comment "Oh shit.. um.."
				
				*comment "You better not be halfway through, or I'll shove my crowbar down your throat!" She angrily scolds her brother.
				
				*comment "I.. um.. may have just finished it.."
				
				*comment "... You owe me a cheeseburger!"
				
				*comment "Okay! sorry.." His voice trails off
			
			*comment "Is there anyone there? You're supposed to be lookout" Uriel says.
			
			*comment "Nah, no one's here.. just me and the ${heistvehicle}.. There was a fly a few minutes ago but I got it out.."
			
			*comment "Alright just keep an eye out. Tell me if you see anything" You say to him.
			
			*comment "Roger that, governor!"
			*comment *goto return
		*comment *if (S_token = 2) #".. Are you listening to the radio?"
			*comment *set RelCarly +3
			*comment "Yes, I mean, what else am I supposed to do? I'm just waiting on you three"
			
			*comment "Is there anyone there? You're supposed to be lookout"
			
			*comment "No, no. No one's here. Just me and the ${heistvehicle}. There [i]was[/i] a squirrel in the parking lot a few moments ago, but I think something scared it away.."
			
			*comment "Alright just keep an eye out. Tell me if you see anything" You say to her.
			
			*comment "Yes sir! My eyes are open"
			*comment *goto return
		*comment #"We're good, how are you?"
			*comment *set RelCharlie +2
			*comment *set RelCarly +2
			*comment "Sleepy, but doing well. Thanks for asking. How's the robbery going?"
			
			*comment "We're at the loot, should be done in a few.."
			
			*comment "Oh, great to hear! I'll be in the ${heistvehicle} if you need me.."
			*comment *goto return
		*comment #"We're at the loot, should be done in a few.."
			*comment "Oh, great to hear! I'll be in the ${heistvehicle} if you need me.."
			*comment *set RelCharlie +1
			*comment *set RelCarly +1
			*comment *goto return
		*comment #"Shut up and just wait for us"
			*comment *set RelCharlie -4
			*comment *set RelCarly -4
			*comment *if S_token = 1
				*comment "Sorry, jeez. I was just starting a conversation.." He stops talking.
			*comment *if S_token = 2
				*comment "Oh.. uh. Sorry.." She stops talking.
			*comment *return
*return

I’m gonna try and see if the problem is actually in the label previous of the *gosub command…

What’s the initial subroutine call look like?

*gosub Heist2BSceneEnd
*gosub OPPalarmcheck2
*rand countslot2 95088 95089
*comment ^^ indicator for randomtest to see if whether or not it actually goes through the whole label
*goto Heist2BScene2

All labels are in the same scene. I went through Heist2BSceneEnd, and it successfully returned. Also, indicator did not show on randomtest… meaning it didn’t go through OPPalarmcheck2

Update: Okay so… I did something, not exactly sure what it was, but it finally went through OPPalarmcheck2.

It went through a few more indicators this time, however, it stopped within these lines.

*label Heist2BScene2
*rand countslot2 12 12
*comment ^^ indicator for randomtest
*set SPlabel "saveHeist2BScene2"
*gosub_scene SP savepoint
*rand countslot2 13 13
*comment ^^ indicator for randomtest
*label saveHeist2BScene2
*if HeistChoice7 = 1
	You continue breaking open the jewellery boxes and pouring the various earrings and necklaces into your duffel bag.
	*if HeistChoice4 = 1
		Uriel 
		*if HeistChoice5 = 1
			and Ramiel
		*if HeistChoice6 = 1
			and Sariel
		continues to work on the boxes with you, opening them and pouring their insides into the duffel bag with haste.
	*if (HeistChoice5 = 1) and (HeistChoice4 != 1)
		Ramiel
		*if HeistChoice6 = 1
			and Sariel
		continues to work on the boxes with you, opening them and pouring their insides into the duffel bag with haste.
	*if ((HeistChoice6 = 1) and ((HeistChoice4 != 1) and (HeistChoice5 != 1)))
		Sariel continues to work on the boxes with you, opening them and pouring their insides into ${Shis} own duffel bag with haste.
	*if HeistChoice4 != 1
		*if HeistChoice5 != 1
			*if HeistChoice6 != 1
				Looting all these boxes by yourself has proven to be quite the endeavour.
*if HeistChoice7 = 4
	You continue to stand by the window 
	*if HeistChoice4 = 4
		with Uriel
		*if HeistChoice5 = 4
			and Ramiel
	*if (HeistChoice5 = 4) and (HeistChoice4 != 4)
		with Ramiel
	and you hear the distant sound of sirens, quite far away.
	*if HeistCondition = 3
		It appears to be getting louder and louder. It sounds to be coming your way. You ready your weapon.
	*if HeistCondition != 3
		It appears to be getting quieter and quieter. You don't think it's coming your way. You sigh in relief.
*rand countslot2 14 14
*comment ^^ indicator for randomtest
*comment URIEL ROLE
*line_break
*line_break
*if HeistChoice4 = 
	Uriel says to you as ${Uhe} unlocks one of the boxes "Who did you say owned this store again?"
*if HeistChoice4 = 2
	Uriel shouts out from the back room as ${Uhe} continues to pick the lock on the safe "Who did you say owned this store again?"
*if HeistChoice4 = 4
	Uriel says to you as ${Uhe} looks out onto the streets "Who did you say owned this store again?"
*comment RAMIEL ROLE
*line_break
*line_break
*if HeistChoice5 = 1
	Ramiel replies for you as ${Rhe} continues to open the jewellery boxes "I think Gabriel mentioned the name Rocco Salvatore..."
*if HeistChoice5 = 4
	Ramiel replies for you as ${Rhe} continues to stare out the window "I think Gabriel mentioned the name Rocco Salvatore..."
*comment SARIEL ROLE
*line_break
*line_break
*if HeistChoice6 = 1
	"Why does that name sound familiar?" Sariel asks as ${She} pours the jewelries into ${Shis} duffel bag.
*if HeistChoice6 = 4
	"Why does that name sound familiar?" Sariel asks through the radio as ${She} stays in the getaway vehicle, staring down the street.
*comment YOUR ROLE
*line_break
*line_break
"Isn't he that famous prostitute?" Uriel asks.

"Adult Films Actor" Ramiel corrects ${Uhim}.

"What's the difference?" Sariel asks.

"One's illegal, the other's a profession" Ramiel replies, inviting a chuckle from Uriel.
*rand countslot2 15 15
*comment ^^ indicator for randomtest
*fake_choice
	#"Would robbing count as a profession?"
		"Anything's a profession if you get paid" Gabriel replies in your radio.
		
		"Doesn't that mean prostitution is also a profession?" Sariel asks.
		
		"If someone's willing to pay, then yes" Gabriel answers.
		
		"But it's illegal" Ramiel says.
		
		"So is stealing..." Gabriel replies. "Nothing's illegal if you don't get caught" He says.
	#"Everyone, focus on your work"
		"Right.. sorry"
		*if HeistChoice6 = 1
			Sariel says as ${She} continues to pours the jewelries into ${Shis} duffel bag.
		*if HeistChoice6 = 4
			Sariel says through the radio. "Eyes on the road.." $!{She} says.
	#Say nothing.
You take time to look at your surroundings. Everyone in your crew appears to be busy working on their assigned task.

*rand countslot2 16 16
*comment ^^ indicator for randomtest
*gosub Heist2BSceneEnd
*gosub OPPalarmcheck3

Now, in the randomtest,

HeistModule *rand countslot2 11
HeistModule *rand countslot2 12
HeistModule *rand countslot2 13
HeistModule *rand countslot2 14
RANDOMTEST FAILED: TypeError: stack[0] is undefined

the whole thing stopped right after 97088… however, it didn’t show the lines above it for some odd reason.

I added a variable display script right after 97088, to see whether or not the HeistChoice7 is correctly set, and it was set as 1

So… how come it didn’t show the line above it? And why did it not reach indicator 15 and 16?

I don’t think you are allowed to add *if’s like that within a *fake_choice. I think you have too many clauses - you might get away with 1 if, but 2 as you have it might cause problems.

Of course, I might be wrong as I’ve never tried that many, but it could be worth testing.

Otherwise, I can’t see anything obvious.

Edit: Wow, that took me a long time to reply - I didn’t see the subsequent messages.

You have an unfinished line:


*if HeistChoice4 = 
	Uriel says to you as ${Uhe} unlocks one of the boxes "Who did you say owned this store again?"
*if HeistChoice4 = 2

*If HeistChoice4 = … what?

4 Likes

Good god, I feel like an idiot…

:rofl: Thank you so much @andymwhy ! It did the trick!

EDIT: This thread is now solved, can someone please close this. Thank you so much to those who’ve helped me!

1 Like

FYI, this error message is fixed in the latest version of ChoiceScript on GitHub. If you upgrade to the latest version and make a similar mistake, it will say something like this:

startup line 33: Invalid expression at char 14, expected something after a =

5 Likes