0 votes
by (130 points)

Hi everyone, sorry to bother you all with such a basic question.

I'm trying to do a simple "if - else" process, and I keep getting an error message. I'm just trying to get Twine to recognize when the random number doesn't fall in a certain range. For the life of me, I can't figure out what I'm doing wrong.

This is the code I'm trying to get to work:

<<set $RandomNumberA to random(1,10)>>

<<if $RandomNumberA gt 5>>

<<set $HighRandomNumber to true>>

<<else>>

<<set #HighRandomNumber to false>>

<<endif>>

<<print $RandomNumberA>>
<<print $HighRandomNumber>>

If the random number is greater than 5, everything works okay. But if the random number is less than 5, I get this error message.

Error: <<set>>: bad evaluation: Invalid or unexpected token

I am completely stumped. Thanks in advance for your help.

1 Answer

+1 vote
by (68.6k points)

Look at your <<set>> more closely, you bobbled the variable name.  You wrote #HighRandomNumber as opposed to the correct $HighRandomNumber.  In other words, this:

<<set #HighRandomNumber to false>>

Should be the following instead:

<<set $HighRandomNumber to false>>

 

ALSO: The <<end…>> forms have been deprecated for approximately forever now, you should be using the <</…>> forms, as shown in the official documentation (i.e. instead of <<endif>>, should use <</if>>).

by (130 points)
Thank you very much, I don't know how I could have missed that. I greatly appreciate your help!
...