Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

using boolean AND -- twine 1.4.2

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

  • In the future, please use a code block (it's the 'C' on the edit bar).


    You have a spurious 'if' after the logical-AND operator. For example:
    → Incorrect
    <<if $strikes eq 1 && if $prepared is 'yes'>>
    
    → Correct
    <<if $strikes eq 1 && $prepared is 'yes'>>
    
    → Also, correct
    <<if $strikes eq 1 and $prepared is 'yes'>>
    

    That said, what you want to do:
    <<if $strikes eq 0>>
    Because you did your homework and got enough sleep, you ace the quiz!
    <<endif>>
    <<if $strikes eq 1 && $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>>
    
    Is not the same, logically, as what you are doing now:
    <<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>>
    
    For example. If $strikes is 0, your current code yields:
    Because you did your homework and got enough sleep, you ace the quiz!
    
    The code you want to use, on the other hand, yields:
    Because you did your homework and got enough sleep, you ace the quiz!
    You're unprepared for the quiz, but because you're well-rested, you muscle through the quiz and get a B.
    
    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:
    → Nested $prepared condition
    <<if $strikes eq 0>>
    Because you did your homework and got enough sleep, you ace the quiz!
    <<elseif $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>>
    
    → Conjoined $prepared condition
    <<if $strikes eq 0>>
    Because you did your homework and got enough sleep, you ace the quiz!
    <<elseif $strikes eq 1 and $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>>
    
    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:
    → $prepared: 'yes' or 'no'/''
    <<if $prepared is 'yes'>>
    <<if $prepared is 'no'>>
    
    → $prepared: true or false
    <<if $prepared>>
    <<if not $prepared>>
    
    The latter is much better.
Sign In or Register to comment.