Howdy, Stranger!

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

variables and if in 2.0.2

I got this:

<center>(if: $wayone = 0)[(link: "Minus")[(goto:"subtraktion")] |](if: $waytwo = 0)[(link: "Addition")[(goto:"addition")] |]</center>

[(if: $waytwo = 1) "hello"]

$waytwo

In the passage before I set $waytwo = 0.
First time I enter this passage $waytwo is 0, great!
But Hello is visible. Not good.

If I click addition and go back, I get $waytwo set to 1.
Then Hello should be visible and menu addition should not be shown.

What am I doing wrong here?

Comments

  • You should be testing equality with the key word is.

    In programming "=" on its own is always used to set a variable and "==" is used to test the value of a variable - otherwise, how is the computer to know the difference?

    Twine 2 does not recognise "==" as a method for testing the value of a variable.

    To avoid this problem altogether use to and is.
    (set: $myValue to 1)
    (if: $myValue is 1)[Hello]
  • I've got an exact same problem, but with more simplified code, really. I've tried to have two passages linked to the main one. One passage generates: (set: $key to 1) for the "key" to a chest, the other generates: (set: $key to 0) for the actual "chest".

    The second passage with the chest also has:
    (if: $key is 1)[[open]]

    Same issue as above, even if the key is generated to 0, the link still displays. I tried to do it with letters just to get the same effect. Another version I tried to do was with (if: (history:) contains "key")[[open]] in the "chest" passage. Sad to say that nothing changed - the link is still there, taunting me.

    One thing that might have happened was that the (if:) statements are taking in the account the set variables from the entire file, rather than that specific passage, but then again why is (history:) not working either? Strange. I've done this trick with generated variables before, and it worked as intended. However, I've accidentally deleted that file, so I can't be certain that what I've done matches what I'm doing right now.
  • Your problem is slightly different.

    You've misunderstood the difference between a hook and a link. This is a hook:
    [This text is inside a hook]
    This is a link:
    [[This text is inside a link]]
    If you want to use a link inside a hook you must use both.
    (if: $key is 1)[[[open]]]
  • Got it, thanks. I tried putting the hyperlink in brackets, but I guess i had to put spaces in between the hook and link brackets because without it, it just generated a new passage named "[name"

    That also took me three days of crying over what's wrong with my strings when all it was was just formatting. Thanks again
Sign In or Register to comment.