0 votes
by (630 points)

Apologies if this has already been covered, I've searched the new and old forums and haven't found anything on this particular error.

I have a very simple Boolean test for a player score report.  It goes something like this:

(set: $p1Score to 5)\
(set: $p2Score to 10)\

(if: $p1Score > $p2Score)[Player 1 is ahead.]\
  (else-if: $p2Score > $p1Score)[Player 2 is ahead.]\
  (else-if: $p1Score = $p2Score)[Players are tied.]

When I run it, I get the following error:

Player 2 is ahead. (elseif:)'s 1st value is a 'to' or 'into' expression, but should be a boolean.►Players are tied.

If I expand the error, I see the following text: "If you gave a number, you may instead want to check that the number is not 0. If you gave a string, you may instead want to check that the string is not ""."

Am I missing something when it comes to Boolean operators?

I'm using Twine 2.1.3 on MacOS Sierra, Story Format Harlowe 2.0.1

 

1 Answer

+2 votes
by (63.1k points)
selected by
 
Best answer

The equal sign is the assignment operator in JavaScript; it's equivalent to 'to', hence the error message referring to 'to' and 'into'. You need to use the 'is' operator for comparisons: 

(else-if: $p1Score is $p2Score)... 

That said, you don't really need the comparison at all; you could just use (else:) since the only other value possible that doesn't satisfy either of the other conditions is if they're equal. 

(set: $p1Score to 5)\
(set: $p2Score to 10)\

(if: $p1Score > $p2Score)[Player 1 is ahead.]\
(else-if: $p2Score > $p1Score)[Player 2 is ahead.]\
(else:)[Players are tied.]

 

by (630 points)
Wow.....I feel like a total idiot.  I've been using "is" for ages, but didn't realize that = wouldn't work.

 

Thanks as always Chapel
...