Howdy, Stranger!

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

(Harlowe) My variables never seem to work.

Here's my text in a Twine 2 story using Harlowe.

(if $hasgrenade is true)[Grenade!]

However, once I test it, it always shows this instead:

(if 0 is true)[Grenade!]

What am I doing wrong here?

Comments

  • missing a colon after if for a start.

    (if: $hasgrenade is true)[Grenade!]

    you will also have to set $hasgrenade as true further up.

    (set: $hasgrenade to true)
  • missing a colon after if for a start.

    (if: $hasgrenade is true)[Grenade!]

    you will also have to set $hasgrenade as true further up.

    (set: $hasgrenade to true)

    Awesome, thanks a lot!

    Is there a quick and easy way to change the variable as part of that hook?


  • Not sure what you mean...

    Manual is worth a look if you haven't already: https://twine2.neocities.org/
  • In Harlowe any variable you don't manually assign an initial value to using a (set:) macro will default to zero, this is why it is a good idea to initialise all the variables you plan to use within your story at the start.

    You can do this within a startup tagged passage like so:
    (set: $hasgrenade to false)
    (set: $hasSword to false)
    (set: $hasHelmet to false)
    (set: $health to 100)
    

    When checking if a Boolean expression like a variable is equal to true or false within an (if:) macro yo don't need to include the is true or is false part of the expression.

    The following shows two examples of a more correct way to test if a Boolean variable is true or false:
    (if: $hasgrenade)[The main character has a grenade!]
    
    or
    
    (if: not $hasgrenade)[The main character does not have a grenade!]
    

    The Twine Passage editor has colour syntax highlighting, if your macro is correctly formatted then the macro name will change black to a red-ish colour and if the associated hook of a valid macro is formatted correctly the related open and closed square brackets will become bold.

    So if you look at both your original (if:) macro example along with Jumpovertheage and my examples you will see the difference in colour syntax highlighting.
    (if $hasgrenade is true)[Grenade!]
    
    (if: $hasgrenade is true)[Grenade!]
    
    (if: $hasgrenade)[The main character has a grenade!]
    
    ... your's will have a black macro name whereas the other two will be red-ish.
Sign In or Register to comment.