Conditional help

Twine 2
Harlowe 3.01

Hi this is my first time using Twine.
I have set a variable to boolean true in one passage using (set:$revealed010Go=true) and the debug shows it as being set to true at the correct time. I have another passage where I want to set a link depending on this variable, so I tried the following:
(if: $revealed010Go is true)[[Head South->010Go][
(else:) [[Head South->010Gr]]

but I get an error at runtime saying “there’s nothing to do before this to do (else:) with”

If I make it as single [ ] it works OK, i.e displays the correct text, so I guess I can’t use this conditional with links?

What should i be using instead - i basically want a link that says ‘Head South’ which goes to either 010Go or 0101Gr depending on the value of the variable.

Thanks for reading!


1 Like

This is a little tricky, because both the if part and the else part need to be inside a “hook”, which uses single square brackets:

So theoretically you’d need triple square brackets (one set for the hook, two for the link) but IIRC this confuses the twine editor. You can get around that by putting spaces in: (if: $revealed010Go is true)[ [[Head South->010Go]] ](else:)[ [[Head South->010GR]] ]

If you’re in a situation where the extra spaces are annoying, you can use the (link-goto:) macro instead:

(if: $revealed010Go is true)[(link-goto: "Head South", "010Go")]
(else:)[(link-goto: "Head South", "010Gr")]

But this has the disadvantage that the Twine editor won’t show arrows between the passages. There might be some other workaround that I’m not thinking of…?

1 Like

Thanks for that! That actually worked OK even without the spaces.

I have subsequently decided to try it in SugarCube, and your method worked well in there:

<<if $revealed010Go is true>>
[[Head South->010Go]]<>[[Head South->010Gr]]

1 Like

Ah, cool. Note that you’ll want to use preformatted text for SugarCube code (and ideally for any code) since the forum thinks that the < and > mean it’s HTML. So you can put backticks around your code, or select it and hit the </> icon in the icon bar above the forum’s text box.

<<if $revealed010Go is true>>
	[[Head South->010Go]]
	[[Head South->010Gr]]

A bit like that - thanks!

1 Like