0 votes
by (140 points)

On the second screen of this Twine, there is a link reading "Test vines." When you click it, that link is replaced with the text "You tug the vines. They should hold." I want to do this.

I want to be able to replace and reveal text within one uninterrupted screen in a simple way.

I could only find ways to do this involving variables or dice rolls, etc., and I had no idea how to take that stuff out without wrecking it. I might not have understood how to word my question when searching for it.

4 Answers

+1 vote
by (8.8k points)

I'm a TWINE noob, so this may not be the most elegant way to do this, but this should work.

Passage name: The wall of vines

You are at a wall covered in vines.

<<if ndef $vines>>[[Test the vines|The wall of vines][$vines to 'tested']]<<else>>You tug the vines.  They should hold.<</if>>


by (140 points)

Thanks for the quick reply! I'm a total noob, too.



And when you click that...

https://i.gyazo.com/70ad3975bc65f6acfcaa9a11dd9d7404.png the page changes entirely.

Unfortunately, it didn't work out on my end. Maybe I didn't get something?

by (8.8k points)
Ah, yeah!  I think you have two passages, one called "Charlie help" and one called "The wall of vines".  

You should only have one passage, called "The wall of vines".  That might fix it.  (Although litrouke's answer might be a better solution!)
by (140 points)

I did. AND, yours works perfectly too!! I'll use litrouke's for now, I think, BUT you nailed it.
+3 votes
by (1.7k points)

Scroll all the way down to add-ons for Sugarcube 2 on this page. Follow the instructions in the zip file, and use the replacelink macro for exactly what you need. Once you have the add-ons "installed" in your Twine game, all you need to do is this:

<<replacelink>>Before a click.<<becomes>>After a click.<</replacelink>>

Happily, no need for any dice rolls or complicated stuff!

by (8.8k points)
I've just found out that there's a macro in Sugarcube 2.8.0 that does this, no need to even install the add-on!

<<linkreplace "Test the vines.">>You tug the vines.  They should hold.<</linkreplace>>
by (140 points)
1) Do you mean 2.18.0, not 2.8.0?

2) Is there a resource with examples?

2) Is there a Sugarcube 2 macro for clicking a link and making text appear under it without replacing anything (and making the link become normal text after 1 click)?
by (140 points)
edited by
Also, I seem to have trouble installing the plugin. Whenever I open Twine, the plugin disappears from my story. It saves edits I make within Twine, so I don't know why this is happening!

Putting it in before opening Twine: https://i.gyazo.com/af8d5170b1d333c1870bfb4462d1721f.png

Checking out the story: https://i.gyazo.com/ef3397f06663cd279f05f2a2e41f474d.png

Closing Twine, opening story html: https://i.gyazo.com/9613d0dba862b4e8f1ea1f4334d8030c.png (notice how much sorter the scrollbar is)
by (65.8k points)

That is not how you install the add-on.  Did you read the included README?  From the Installation section:


  1. Open the replacelink-macro-set.min.js file in a text editor (not a word processor) and copy its contents.
  2. Paste them into your project's script section (Twine 1: script-tagged passage, Twine 2: Story JavaScript).


  1. Open the replacelink-macro-set.css file in a text editor (not a word processor) and copy its contents.
  2. Paste them into your project's stylesheet section (Twine 1: stylesheet-tagged passage, Twine 2: Story Stylesheet).

As you're using Twine 2, you need to paste the contents of the JavaScript file into your project's Story JavaScript.  Similarly, the contents of the CSS file goes into the Story Stylesheet.  You'll find both listed under your project's story menu.

by (65.8k points)

1) Do you mean 2.18.0, not 2.8.0?

Not quite.  They meant that the macro was added to SugarCube as a part of v2.8.0.


2) Is there a resource with examples?

SugarCube's Macro Library documentation does include a few examples for each macro.  They're not exhaustive, but they cover the basics.  Also, reading other parts of SugarCube's documentation may prove helpful.


2) Is there a Sugarcube 2 macro for clicking a link and making text appear under it without replacing anything (and making the link become normal text after 1 click)?

Yes.  You're looking for the <<linkappend>> macro.

+1 vote
by (65.8k points)

If you only have one, or very few, options to cycle through, the built-in <<linkreplace>> macro is probably what you want.  For example:

<<linkreplace "Test the vines.">>You tug the vines.  They should hold.<</linkreplace>>

If you want to cycle through more than a few, then you're probably better off with litrouke's answer.

by (140 points)
edited by
Thank you!

Is there a way to put a link replace within a link replace? I can't get it to work.
by (65.8k points)

Yes, though how you'd nest them depends on what you want to do.

A basic one-way becomes example: (using line continuations for readability)

<<linkreplace "Alfa">>
\<<linkreplace "Bravo">>
\<<linkreplace "Charlie">>

Another example: (again, using line continuations)

<<linkreplace "Alfa">>

<<linkreplace "Charlie">>

<<linkreplace "Echo">>


Those are simply two examples, others are possible.  Additionally, you may want to look into the other <<link>> family Interactive macros and the DOM macros (see: SugarCube v2 Macro Library) as they would give you extra flexibility.

0 votes
by (790 points)

There are a couple of ways to do this.

1: As noted already, you can use a Linkreplace. It's quick and easy to do. For a basic little replace, it works great. =^^= The addon replacelink, I have not used.

2: Combining a Link macro AND a Replace macro can get you the same effect, but offer up some more versatility. You likely wouldn't need it for that vine test, but for other things, this comes in VERY handy.

(If you're not a programmer, this is probably going to look scary, but once you start to learn your way around the code, this will work wonders for you. Just don't panic. =^^= )

First, a quick explanation.

<span></span> Spans are telling the system "hey! This piece of the page is different from the rest of it!" a span is usually used to give text special colors and features through a class (that's CSS code, i won't get into that), and ID. The ID gives the span a name that can be referred to by other pieces of code. I'll get into that with something in a minute here. basically... <span id="namethistext" class="dontworryaboutmenow"></span>  Just keep in mind that spans have only single brackets, <> as opposed to a lot of other code that has two <<>>.

<<link "text">><</link>> basically turns the text between the quotation marks into a link. When the player clicks on that text, any code contained between the link and endlink is performed. (if you see a link with a second line of text in quotation marks <<link "text" "place">> the second one is the name of a passage to go to after performing the code in the link)

<<replace "#">><</replace>> This one gets fun. You can use this to replace certain parts of a page with something else. Specifically, you can add in the name of a Span, and replace everything in the Span with what you have placed inside the Replace. (the ID of the span has to have the hashtag added to it for the replace)

<span id="spanname">\
	You see a \
	<<link "Big Red Button">>\
		<<replace "#spanname">>\
			Pushing the button results in the teleportation of bread!!!
		<<set $bread to $bread + 42>>\

	...but maybe you should \
	<<link "not push it..." "that passage without bread">>\
		<<set $bread to 0>>

I added the variable changes just to point out that you can do more than replace text. Using this method is more complex, and certainly more than you need for just replicating the vine test, but if you want your character to remember that they checked the vines, you would probably want to use link AND replace, rather than linkreplace.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.