0 votes
by (170 points)

I've been looking at this guide for Twine: https://twine2.neocities.org

...and it says if statements are for booleans only. I can't seem to find anything in there about some way of making if statements with numbers. Is this not possible?

Example of what I'm talking about, if if statements worked with numbers:

**Depending on the choice the player made, they will be directed to a passage that will either 
(set: $Weight to +1) 
OR
(set: $Weight to +2)**

**No matter what, they will then come to a passage that will (set: $Weight to -1), so $Weight can only ever equal 0 or 1.**

**Later on, a passage link will be visible depending on the $Weight variable. The options will be either:

[[Continue.->Three out of Five]]
(if: $Weight = 1)[ [[Give Avery the paperweight.]]]**

Thanks!

1 Answer

0 votes
by (68.6k points)

What the documentation means is that the conditional expression you give to the (if:) always yields a boolean.  You can use any valid conditional expression, even ones that compare numbers.

In your particular case, you're looking for something like the following: (uses the appropriate Harlowe operator)

[[Continue.->Three out of Five]]
(if: $Weight is 1)[ [[Give Avery the paperweight.]]]

 

Details: The = operator you attempted to use is a JavaScript assignment operator and the equivalent of the Harlowe to operator.  If you really wanted to use a JavaScript operator there, then you'd want the equivalent to Harlowe's is equality operator, which is the == operator.

...