0 votes
by (160 points)
closed by

So, I'm trying to let someone forage for something if their survival level is high enough. Only problem is, I'm guessing it's not registering the variable used as a number, or something.

Here's what I'm trying to make work:

<<if $hasSurvivalbook is true or $skills[3]['lvl'] is gt 2>>They appear to be edible //and// safe. You could <<link "take some">><<set $fruit[0]['amt'] to itself +1>><</link>>. <<else>>You don't know much about the plants here, so you decide to avoid them.<</if>>

I isolated the part I though was wrong, and it gives the same error: (same error occurs if you use > or gt)

<<if $skills[3]['lvl'] is gt 2>><</if>>

This is the error I get:

⚠ <<if>>: bad conditional expression in <<if>> clause: Unexpected token >

This is the array it works off of: 

<<set $skills to [
	{skill:"Attacking", lvl:0},
	{skill:"Defending", lvl:0},
	{skill:"Casting", lvl:0},
	{skill:"Survival", lvl:0}
]>>

The array is loaded way before the part where the block of code comes in, so I'm not sure what the problem is. Please help!

closed with the note: Answered well

1 Answer

+1 vote
by (68.6k points)
selected by
 
Best answer

You're combining operators.  You, generally, cannot not do that.  For example, is gt should simply be gt.  See the <<if>> macro documentation for examples.

Also.  While not incorrect, you generally do not test a boolean values against the booleans literals.  For example, $var is true should simply be $var, $var is false should simply be not $var.

In detail:

/* BAD */
<<if $hasSurvivalbook is true or $skills[3]['lvl'] is gt 2>>…

/* GOOD */
<<if $hasSurvivalbook or $skills[3]['lvl'] gt 2>>…



/* BAD */
<<if $skills[3]['lvl'] is gt 2>>…

/* GOOD */
<<if $skills[3]['lvl'] gt 2>>…

 

by (160 points)
Thanks! did not know about not needing to check booleans!
...