Twine macro: << replace >>, << insert >> and << continue >>

Similar to my <<timedreplace>> macro, this macro creates an internal link that, when clicked, vanishes and is replaced with whatever is between the << replace >> and << endreplace >> tags. This could be useful if (just for starters) you want to have a passage that can be modified by clicking specific details inside it.

* You can also use <<insert>>, which is identical but does not remove the link text, instead merely changing it to a bare <span> (as with Jonah's <<choice>> macro.)
* You can use <<continue>> to make all subsequent text appear when it's clicked. It does not need an <<endcontinue>> at the end! Quite useful when you just need the reader to click to continue the passage.
* You can insert <<becomes>> or <<gains>> tags inside the contained text to create multiple "versions" of the replacement text. Clicking the link will display each successive version, stopping only when the last version is reached.
* If you omit the text in the starting tag, then the first "version" will be used as the link instead. This lets you, for instance, make an image into a replaced link. Of course, this requires that multiple <<becomes>> or <<gains>> tags are within the text.

Install my <<Replace>> Macro Set to use this macro.

Usage examples:
You see <<replace "a half-eaten cake">>a plate of crumbs<<endreplace>>
You see <<replace "ten dollars">>five dollars<<becomes>>two dollars<<becomes>>fifty cents<<endreplace>>
You see <<replace>>a //big// boulder!<<becomes>>some pebbles.<<endreplace>>
I find it <<insert "repugnant">>that he's made such comments<<endinsert>>.
You go outside. <<continue "Next.">>The sun blinds you momentarily.<<continue "Next.">>Has it been so long?

A short example program.
Hot hint: if you've got a lot of text, it's good to just put a single << display >> inside a << replace >>, and put the text in a separate passage.

Some notes:
* Code inside << replace >> tags is only executed when you click the link. You may notice that the "mailbox" link in the example program produces different text if you click the "front door" link first.
* If inserted text appears and descends below the bottom of the screen, the page should automatically scroll down to make it visible.
* Note: due to the way the browser and Twine interact, any changes made by code inside a <<timedreplace>> tag will be forgotten if you use the Back or Forward browser buttons, unless you use this script.

For a more powerful version of this macro, see <<revision>>.

Version history:
* 16-6-2013: Updated regarding Combined Replace Macro Set.
* 26-4-2013: Added << continue >> variant.
* 5-4-2013: Added << insert >> variant, scrolling.
* 7-3-2013: Added CSS hooks.
* 28-1-2013: Initial.
Feel free to report any bugs to @webbedspace.

TwineMacro-ReplaceTest.html186.33 KB
TwineMacros-Replace-1.3.0.txt3.41 KB


Replace Macro

Hey there! Love the work you've done with Twine, it's come in as a lifesaver more than once already in my projects. ^_^

I have a question about the 'replace' macro -- is there a way to make a link of only part of the text to be replaced? As an example I've got the sentence "Off to the side is a stable for the wagon-pulling animals."; I'd like to replace 'stable for wagon-pulling animals' with different text, but having that whole phrase in blue gives it a sort of visual importance outweighing the progress-making links further down. I'd like to make only the word 'stable' the link to replace the whole phrase.

Of course the easiest fix is just to rewrite the passage to flow appropriately, but I have a feeling that I'll be wanting to do the same thing fairly often in my story, so if there's a reasonably simple way to do this I'd be mightily chuffed. Thanks!


A bit late to reply, but try using <<revision>>:

<<revision side>>Off to the side is a <<revise side "stable">> for the wagon-pulling animals.<<becomes>>Some other text.<<endrevision>>

Initialize macro again after start?

Hi there, I love this macro. I was wondering if there's any way to re-initialize it after the start screen? I just realized that, by using the built-in "bookmark the web page" method of saving progress in Twine, the macro breaks and all my beautiful continues and replaces get replaced with ugly red boxes. I'd really like to make it so that this macro automatically restarts on whatever page the player returns to - is that possible? I'd really appreciate the help.

One answer is to use a more

One answer is to use a more recent version of Twine, such as this one.