Lucktest not working and can't see why?

This simple lucktest doesn’t work and I can’t see why?
What should happen is, a random number of 1 to 12 is generated and compared to Luck. Luck has been defined in startup
Instead what happens is that the same score is generated over and over

here is the startup txt:

*create luck 8
*create lucky false
*create lucktext “lucky”

And now the gosub:

*label lucktestgosub
*temp lucktest 0
*rand lucktest 1 12
*if (luck > lucktest)
	*set lucktext "lucky"
	*set luck -1
	*set lucky true
	*set lucktext "unlucky"
	*set luck -1
	*set lucky false

here is the code that shows the score

   #Test your luck
		*gosub lucktestgosub
		You have been ${lucktext} with a score of ${luck}

This text always shows 7, I have tried changing {luck} to {lucktest} but that doesn’t show anything

Apologies, I can’t see what is wrong?

${luck} shows your current luck (created 8, minus 1 in subroutine, equals 7).
I am not sure about why it isn’t showing ${lucktest}. What is you create lucktest in startup instead of making it temporary variable?

1 Like

Thanks indeed, it’s fixed!
Really appreciate your help, I am going to have another coffee as I need it!

1 Like

Just as an explanation. Temp variables exist only in the place where they where created. So after coming Back from the gosub there was no variable called lucktext.


Just FYI, you don’t have to post another thread as a follow-up of your coding problem.

You can edit your posts, both the content and the title, and we can follow them easily as long as you keep us updated. We prefer this place to be tidy, see.