Howdy, Stranger!

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

"If and" statement help?

edited February 2016 in Help! with 2.0
I'm trying to make it to where if the player's relationship count with character Bob is the value 1 or 2, and their name variable isn't or isn't blank, then certain dialogue will show up. I have it like this:

(if: $bobRelationship is 1 or 2 and $name is not "")["I'm sorry, $name."]
(if: $bobRelationship is 1 or 2 and $name is "")["I'm sorry, $defaultName."]

Twine won't allow me to use 'and', so I tried to use '+' instead, but when I do that and $bobRelationship is 2 it will display the first if statement, even if $name is "". If $bobRelationship is 1, then both if statements are displayed! I'm not exactly sure what's going wrong, or how to fix it. I also tried nesting if statements, but that didn't work out.

EDIT

I changed the code, and now the if statements are working sort of. Even if $bobRelationship is 1 or 2, neither of the if statements are showing up. The full code looks like this now:

(set: $followBob to "yes")
(set: $bobRelationship to $bobRelationship +1)
(if: $bobRelationship is 1 or $bobRelationship is 2 + $name is not "")["I'm sorry, $name."]
(if: $bobRelationship is 1 or $bobRelationship is 2 + $name is "")["I'm sorry, $defaultName."]

Comments

  • note: Currently in Harlowe if you don't assign a value to a variable then that variable will equal zero 0, not an empty string "".

    The plus + operator is use to add to values together, try using the and operator instead. You will also need to use parenthesis to control the order the expressions are processed in:

    warning: if $name has not been initialized (assigned a value) before the following code is processed then $name will equal zero when the first (if:) statement is processed, which will result in "I'm sorry, $name." being displayed.
    (set: $followBob to "yes")
    (set: $bobRelationship to $bobRelationship +1)
    (if: ($bobRelationship is 1 or $bobRelationship is 2) and $name is not "")["I'm sorry, $name."]
    (if: ($bobRelationship is 1 or $bobRelationship is 2) and $name is "")["I'm sorry, $defaultName."]
    
Sign In or Register to comment.