Problems with a gosub routine to test luck

I have spent hours on this!
I am trying to create a routine where each time the player tests their luck, the luck stat goes down by 1. So, the more times they test the greater the chance of being unlucky.
I haven’t incorporated dice rolls into thsi yet because I am not able to get my head around that yet.
What I have done is created lucktext and luck in the startup.txt and then the following scene and gosub. The code as is just presents me with the test your luck text and then straight into game over?!

My code looks like this:

You are faced with a choice
*choice
	#Test your luck
		*gosub_scene luckygosub
		You have been ${lucktext} with a score of ${luck}
		*finish


*if (luck > 2)
	*set lucktext ""
*if (luck <= 2)
	*set lucktext "unlucky"
	*set luck -1
	*return

Whats the content of the luckygosub file? The stuff that is after the choice that you posted?

Because if so its working as it should; it will go to the gosub, check if luck is bigger than two (if it is, lucktext will be blank; if not lucktext will be unlucky and will be decreased by 1 and return). The problem here (besides the mutually exclusive if without else) is that you only set the return on the second if. You need to set on both of them or after them so that both go through it otherwise if it goes through the luck > 2 condition it will reach the end of the file without reaching a return (which I think ends the game).

Once the code returns, it will display the You have been ${lucktext} with a score of ${luck} text and then the game will end.

1 Like

Hiya- yes, the gosub file is the one that starts *if (luck > 2)

Thank you for your help, it was not working because it needed an extra return

Appreciated, onwards and upwards!

I recommend you change the bit from:

*if (luck > 2)
	*set lucktext ""
	*return
*if (luck <= 2)
	*set lucktext "unlucky"
	*set luck -1
	*return

to

*if (luck > 2)
	*set lucktext ""
*else
	*set lucktext "unlucky"
	*set luck -1

*return

If you place on the line after the check, it will run for both, no need to include a *return in each.

2 Likes