Random test gosub_scene error

I’m having trouble with a gosub_scene error that only happens in a random test. I also use the same gosub_scene multiple places in the game and the error only appears under one half of a choice option. When the else condition is met random test will error.

The error I’m getting is: RANDOMTEST FAILED: Error: routines line 72: invalid return; we’ve already returned from the last gosub

My code looks like this:

Choice that leads to error
#Third door on the right.
				*set fork 2
				*if (random =0) or (random =1)
					*set Luck +1
					*gosub_scene routines stat_cap
					The placard on the door reads [i]Restrooms[/i]. You hurry through the door hoping they didn't see you come in. There's nothing but empty stalls in the darkroom. You hide in one of the stalls and catch your breath. It only takes a minute before you hear the soldiers rumble past you. You listen. Waiting for someone to kick in the door of your stall.  After a minute of nothing you release the breath your holding.
					*goto bathroom
				*else
					[b]BANG[/b]
					
					A bullet rips through your right shoulder almost sending you skidding past the door. The pain is searing, but you have to keep going.
					
					[i]I thought they were farther behind me![/i]
					
					You scurry through the bathroom hoping they didn't see you come in. There's nothing but empty stalls in the darkroom. You stumble into one of the stalls and catch your breath. The pain from your gunshot wound reminds you it's still there. Gritting your teeth in order not to make any noise you rip off your shirt sleeve and tie it tightly around your shoulder noticing the small droplets of blood on the floor. 
					
					"Shit."
					
					*set Luck -1
					*set Health -20
					*set shot "true"
					*gosub_scene routines stat_cap
					*if Health <15
						*set pow "true"
						*set pow_marker +1
						*goto_scene pow
					*goto bathroom
Where the error happens
*label stat_cap
*if Luck > 7
	*set Luck 7
*if Weapons >100
	*set Weapons 100
*if Explosives > 100
	*set Explosives 100
*if Diplomatic > 100
	*set Diplomatic 100
*if Subterfuge > 100
	*set Subterfuge 100
*if Rebellion > 100
	*set Rebellion 100
*if IIndependent > 100
	*set IIndependent 100
*if IAloof > 100
	*set IAloof 100
*if LIndependent > 100
	*set LIndependent 100
*if LAloof > 100
	*set LAloof 100
*if Agent_kit > 4
	*set Agent_kit 4
*if amlh > 4
	*set amlh 4
*if nine_mm > 16
	*set nine_mm 16
*if mtraderrelationship > 5
	*set mtraderrelationship 5
*if missionone_success > 100
	*set missionone_success 100
*if pool_level >10
	*set pool_level 10
*if Luck < 1
	*set Luck 1
*if Weapons < 0
	*set Weapons 0
*if Explosives < 0
	*set Explosives 0
*if Diplomatic < 0
	*set Diplomatic 0
*if Subterfuge < 0
	*set Subterfuge 0
*if Rebellion < 0
	*set Rebellion 0
*if IIndependent < 0
	*set IIndependent 0
*if IAloof < 0
	*set IAloof 0
*if LIndependent < 0
	*set LIndependent 0
*if LAloof < 0
	*set LAloof 0
*if Agent_kit < 1
	*set Agent_kit 1
*if amlh < 1
	*set amlh 1
*if nine_mm < 1
	*set nine_mm 1
*if mtraderrelationship < 1
	*set mtraderrelationship 1
*if missionone_success < 0
	*set missionone_success 0
*if pool_level <1
	*set pool_level 1
*if Health < 1
	*set Health 1
*if (Health >100) and (flak=false)
	*set Health 100
*if (((Health >115) and (flak=true)) and (plates=false))
	*set Health 115
*if (((Health >120) and (flak=true)) and (plates=true))
	*set Health 120
*return

I’m not sure if this is the problem, but are you using the *return command on the pow scene?

If not, check all the *return commands you’ve used and that the only way there is through a gosub

No returns in the pow scene, but there are gosub_scenes in there… but you don’t come back here after condition.

I want to make sure I understand. Am I checking the scene with the return to see that nothing is taking me to that scene specifically?

Thanks for the help btw. :slightly_smiling_face:

1 Like

Yes, if you hit a *return always have to pass through a gosub before, otherwise you will be trying to return to nowhere, that’s when the error occurs.

No problem, there’s help everywhere around.

I’m still double checking, but I’m not finding anything that shoudn’t be leading me there.

It’s hard to say without looking at all the code, but something is happening there that is trying to return where the stack of directions to return to is empty.

I guess that a global search for the label it’s giving the error will give you a list of all the possible *goto and *gosub that lead there, if you haven’t done that already.

Maybe you can use the *bug command and then run the randomtest with it at different points. Or create a count variable to see how many times the game is going through different paths.

Keep looking because if you’re getting the error it’s because it is there somewhere.

Edit:
Also commenting out all the gotos but one so you can discover which one is faulty might be another thing to try.

1 Like

OMG. One of my gosub_scenes was put in as a goto. Changing that fixed it!

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.