Howdy, Stranger!

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

How to link passages in if statements?

edited November 2015 in Help! with 2.0
I have text thats supposed to display if the player did some specific choice earlier in the game, and in more than a few instances the text that's to be displayed should be a link.

For example, I have this as dialogue an NPC can say to the player:
(if: $goodres >= 0 and $badres is 0)[Well, you're pretty ok so far... (if: $count is true)[and you did count all those buttons...] ok, I think I'm permitted to show you more information.]

I have another if statement that I want to display a passage link if the above count variable is true, but no matter what I try out, it always shows it, regardless of whether or not the variable is true (it passes the badres check, though):
(if: $badres > 1)["No." 

[[Come on, dude.]]

(if: $count is true)[[Does the fact that I counted those buttons mean nothing to you?]]]

I've messed with order of statements and number of brackets, but nothing has helped. I'm still new to programming in this, so I'm sure I've missed something small.


  • edited November 2015
    Assuming that $count is actually a boolean and that the second (if:) is supposed to be inside the first, have you tried something like the following: (tested and working)
    (if: $badres > 1)["No." 
    [[Come on, dude.]]
    (if: $count is true)[Does the fact that I counted those buttons mean nothing to you?]]
    If the content of the second (if:) is supposed to be a link, then it should probably look something like the following:
    (if: $count is true)[ [[Does the fact that I counted those buttons mean nothing to you?]] ]]

    Additionally, all conditionals evaluate down to booleans in the end, so you don't have to compare a boolean value to a boolean literal—just use the boolean value. For example, instead of:
    (if: $count is true)[This shows when $count is true.]
    (if: $count is false)[This shows when $count is false.]
    You can simply do:
    (if: $count)[This shows when $count is true.]
    (if: not $count)[This shows when $count is false.]
  • edited November 2015
    It all comes down to the wrong number of open / close square brackets and a parsing bug related to associated hooks / markup links.

    a. A markup link has two open square brackets at the start and two close square brackets at the end:
    [[The Link Text->The Target Passage Name]]
    [[The Target Passage Name<-The Link Text]]
    [[The Target Passage Name and The Link Text are the same]]
    b. The associated hook of an (if:) macro has a single open square bracket at the start and a single close square bracket at the end:
    (if: $var is "value")[ .... ]
    c. Twine 2 has problems parsing three open square brackets in a row when two of those square brackets belong to a markup link, so you need to add a space character between the first and second square bracket:
    (if: $var is "value")[ [[The Link Text->The Target Passage Name]]]

    Your second code example should be:
    (if: $badres > 1)["No." 
    [[Come on, dude.]]
    (if: $count is true)[ [[Does the fact that I counted those buttons mean nothing to you?]]]]

    note: both the (if: $count is true) in your two examples could be written as (if: $count) because the value in the $count variable is a boolean (true/false)

    edit: TME beat me this time. lol
  • Thanks to both of you! This solved my problem.
Sign In or Register to comment.