Trying to find a replacement for (link:) in SugarCube

Twine Version: 2.3.9
Story Format: SugarCube 2.31.1

I’ve finished a game in Harlowe, and I decided to switch to SugarCube for my next game. In Harlowe you could do this:

(link: "Fight!")[
(set: $FoeHp to 10)
(set: $FoeDmg to 3)
(goto: "Combat")
]

And this would only set those variables if you clicked that link. However, I haven’t been able to find a replacement for this in SugarCube. Is there a macro or some code that replicates this function?

It’s basically exactly the same in sugarcube.

https://www.motoslave.net/sugarcube/2/docs/#macros-macro-link

<<link "Fight!">>
<<set $FoeHp to 10>>
<<set $FoeDmg to 3>>
<<goto "Combat">>
<</link>>

There’s also another method using just a normal passage link.

https://www.motoslave.net/sugarcube/2/docs/#markup-link

[[Fight!|Combat][$FoeHp = 10; $FoeDmg = 3]]

I’m not 100% positive that’s how you do multiple commands in a link setter, but I think so.

1 Like

Yeah, you can use either semicolons or commas to separate each setter.

Also, here are two alternate ways of using the <<link>> macro in addition to the one you showed…

If you don’t want to see the arrows in the Twine editor’s node map, you could do this:

<<link "Fight!" "Combat">>
	<<set $FoeHp = 10, $FoeDmg = 3>>
<</link>>

It’s more compact since it doesn’t need the <<goto>> and it also combines the two <<set>> macros. This is often used in cases where the passage name is held in a variable, because it prevents the Twine editor from creating a passage with the variable’s name, which you’d then need to delete, causing the editor to display that as a broken link, even though it works just fine.

Alternately, if you do want to see the arrows in the Twine editor’s node map, you could do this instead:

<<link [[Fight!|Combat]]>>
	<<set $FoeHp = 10, $FoeDmg = 3>>
<</link>>

That will then show an arrow going from that passage to the “Combat” passage in the node map.

Enjoy! :grinning:

1 Like