What's wrong with this code?

squiffy.set("randomnumber", Math.floor(Math.random() * 20) + 1);

You rolled a {randomnumber}.
{if randomnumber > 10: A decent result...}{else: Hmm, not too good...}

The above always prints 'A decent result', even when the roll is 10 or less...


There should be no spaces in your ">" statement.

{if randomnumber>10: A decent result...}{else: Hmm, not too good...}




However there's also an old bug in ">" and "<" statements that's caused me pain and suffering from time to time. So if this doesn't work, try:

{if randomnumber>=11: A decent result...}{else: Hmm, not too good...}

OR

{@randomnumber+=1}
{@randomnumber-=1}
{if randomnumber>10: A decent result...}{else: Hmm, not too good...}

If it continues to cause you unwarranted agony, just go with javascript if statements.


Yeah… everything between the colon and the greater than/less than sign is taken as the attribute name. So it's looking for an attribute named randomnumber  including the space.


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums