Howdy, Stranger!

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

How do I code 'if' variables?

edited March 2016 in Help! with 2.0
I'm really new to Twine and I'm using it for a project.

I found a couple of different codes for possible instances around the forums, but I can't find the codes for 2.0/Harlowe. I want to be able to let the player pick up an item, have the game remember that they have the item, and then provide another possible option when you go back to the previous page.

i.e. you have the option to run away, but if you picked up a weapon, the game remembers and will also present the option to attack.

Hope this makes sense.

Comments

  • I suggest having a quick look at the Harlowe Manual, it contains information about that Story Format.

    You can use the (set:) macro and a variable to track if the character has a weapon or not. You would initialize (assign a default value) the variable to false at the start of your Story using code like the following, I would suggest placing it in a startup tagged passage.
    (set: $weapon to false)
    
    ... and then change the variable to true when the character picks up the weapon, something like the following:
    (link: "Pick up weapon")[(set: $weapon to true)]
    
    You can use an (if:) macro to check the current value of the variable to determine what to show to the Reader. Because the variable is storing a true/false value you don't need to use the is operator when checking the value.
    (if: $weapon)[The character has a weapon]
    (else:)[The character does not have a weapon]
    
    or
    
    (if: not $weapon)[The character does not have a weapon]
    (else:)[The character has a weapon]
    
  • Thank you very much! It's working perfectly now.
Sign In or Register to comment.