Hello,
I have attached pop_quiz_3variables.tws and pop_quiz--boolean_and.tws (created in Twine 1.4.2) and have a question about the "Pop Quiz" passage. Specifically, I would like to use the boolean && rather than have an embedded if statement. I thought I had it coded properly. The embedded code (which works) looks like this:
<start embedded code>
Mrs. Einstein announces that there's a pop quiz!
<<if $strikes eq 0>>
Because you did your homework and got enough sleep, you ace the quiz!
<<endif>>
<<if $strikes eq 1>>
<<if $prepared is 'yes'>>
You're tired because you didn't get enough sleep, but you were prepared enough to get a B on the quiz.
<<else>>
You're unprepared for the quiz, but because you're well-rested, you muscle through the quiz and get a B.
<<endif>>
<<endif>>
<end embedded code>>
I tried changing this to the following (<<if $strikes eq 1 && if $prepared is 'yes'>> -- see below), which doesn't work:
<start boolean and test>
Mrs. Einstein announces that there's a pop quiz!
<<if $strikes eq 0>>
Because you did your homework and got enough sleep, you ace the quiz!
<<endif>>
<<if $strikes eq 1 && if $prepared is 'yes'>>
You're tired because you didn't get enough sleep, but you were prepared enough to get a B on the quiz.
<<else>>
You're unprepared for the quiz, but because you're well-rested, you muscle through the quiz and get a B.
<<endif>>
<end boolean and test>
I get error message saying "bad expression."
Thanks for any help with this.
Richard
Comments
You have a spurious 'if' after the logical-AND operator. For example:
That said, what you want to do: Is not the same, logically, as what you are doing now: For example. If $strikes is 0, your current code yields: The code you want to use, on the other hand, yields: I doubt that those conflicting results are what you actually want.
To fix that, you should likely be using an <<elseif>> there. Based on what you've shown, I can't say for certain if the $prepared condition should be conjoined with $strikes eq 1 or not—though, based on the text I suspect that it should remain nested. Regardless, you should probably be doing one of the following: Additionally, while it's not possible to tell simply from what you've shown, I suspect that $prepared is being used as a boolean ('yes' and 'no'/''). If so, just use real booleans (true and false) instead. For example: The latter is much better.