0 votes
by (270 points)
So my problem is that the <<link>> command in sugarcube 2.0 runs silently and dosen't print out anything. I don't want this. I need some sort of an interactive button command that is capable of running a single if statement. And is capable of printing out text.

I even found an answer on this site but unfortunately, I can't get it to print out a command.

I'm pretty much new to Twine. So sorry if this is a bit of a noob question

2 Answers

0 votes
by (159k points)
selected by
Best answer

You have a number of options depending on exactly where you want the "printing out text" to appear on the page.

1. The <<linkreplace>> macro suggested by @Chapel
This macro will replace the Link Text with the content of the macro's body.

<<set $variable to "value">>\

<<linkreplace "Option 1">>
	\<<if $variable is "value">>Replacement for link text<</if>>

2. A <<link>> macro combined with a <<replace>> macro
The <<replace>> macro needs a target (like a span element with an ID) and will replace the current contents of that element with the macro's contents.

<<set $variable to "value">>\

<<link "Option 2">>
	\<<if $variable is "value">>
		\<<replace "#output">>
			\Replacement text for output span element

<span id="output"></span>

... the ID'ed element can be positioned either before or after the link itself, and you can replace the <<replace>> macro with one of the other DOM Macros

0 votes
by (63.1k points)

The reason the <<link>> is silent is because there's no real place for the content to go. You need to either a) define such a place and use the DOM macros (<<prepend>>, <<append>>, <<replace>>) to place content, or use one of the three macros that does this for you relative to the link (<<linkreplace>>, <<linkappend>>, <<linkprepend>>). 

An example using <<linkreplace>>: 

<<linkreplace "Click me">>hi<</linkreplace>>