Howdy, Stranger!

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

If and Then in Harlowe - help with syntax please

Hi. I'm working in Twine 2 in Harlowe. I'm struggling with this If loop. It's basically " If this variable is >0 show some text and a link, otherwise show two links"

(if: $splints >0)[Fortunately you have brought spare shin splints.

Continue -> Challenge 4: Anna arrives
]

(else:)[
(link:"Go to the other team and ask for spares")[(set $score to $score +1)(goto:"3a")]

(link:"Tell Rashida to go over to the other team and ask for spares")[(goto:"3b")]

]



If I set $splints to 1, the first part displays and the link works. But with $splints as 0 the second part displays but the links give an error message "(set 0 to 0 +1)I can't (go-to:) the passage '3a' because it doesn't exist."

3a and 3b do exist, of course.

Could someone please advise me on the right syntax?

Comments

  • edited May 2016
    The syntax you're using for the (goto:) is correct. Based on the double square-bracketed link in your example, your problem is likely whitespace.

    You should never put spaces around the text and link components of a link. For example:
    [[Continue -> Challenge 4: Anna arrives]]
    
    Which should actually be:
    [[Continue->Challenge 4: Anna arrives]]
    
    The reason you shouldn't do that is because Twine 2's passage auto-creation code will create the passage with the name " Challenge 4: Anna arrives"—note how it starts with a space, which you likely did not intend.

    If you're certain that the "3a" and "3b" passages exist, then ensure that they don't actually start with a space, because that will cause (goto: "3a") to fail as "3a" and " 3a" are different things.

    Editing the passage and correcting its name should automatically correct all associated double square-bracketed links for you, so you shouldn't have to worry about doing that manually.


    PS: Your (set:) is missing its colon. In other words, this:
    (set $score to $score +1)
    
    Should instead be:
    (set: $score to $score + 1)
    
    Or better:
    (set: $score to it + 1)
    
  • Following your advice I discovered there were spaces at the start of '3a' and '3b' - thanks for the tip-off, and for noticing the 'set' colon was missing.

    Much appreciated!
Sign In or Register to comment.