Add-ons / <<replacelink>> Macro Set

SugarCube version of Leon's Combined Replace Macro Set.

Author Thomas M. Edwards
Website http://www.motoslave.net/sugarcube/2/#downloads
Story format SugarCube 2
Last checked Sun Nov 27 2022
License BSD 2-Clause "Simplified" License
Download replacelink.zip

Index

Overview

SugarCube is a free (gratis and libre) story format for Twine/Twee, based on TiddlyWiki.

The macros included within this set are based upon the Combined Replace Macro Set (v1.1.7) by Leon Arnott <l_1_l_0@yahoo.com>.

This package contains a SugarCube compatible version of the Combined Replace Macro Set. It is intended for use with SugarCube and will not work with other story formats (see the link above for the non-SugarCube version).

📝 Note: All responsibility for this version of the macro set falls upon me (Thomas M. Edwards <tmedwards@motoslave.net>). Please, do not bother Leon if you have issues with it. Address all issues to me, if it turns out to be problem with the base macro set, and not my modifications, then I'll let Leon know about it.

Requirements

This package requires SugarCube v2.0.0 or greater.

Contents

The files included in this package are:

Installation

JavaScript

  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.

Stylesheet

  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.

Macros

<<insertlink>>

Triggered by clicking the content.

READ: Documentation (see Add-ons section).

<<timedinsert>>

<<timedinsert>>

Triggered by time.

READ: Documentation (see Add-ons section).

<<insertion>>

<<insertion>>

READ: Documentation (see Add-ons section).

<<later>>

<<later>>

Triggered by visiting the passage a certain number of times.

READ: Documentation (see Add-ons section).

<<keyinsert>>

<<keyinsert>>

Triggered by pressing a key.

READ: Documentation (see Add-ons section).

<<replacelink>>

Triggered by clicking the content.

READ: Documentation (see Add-ons section).

<<timedreplace>>

<<timedreplace>>

Triggered by time.

READ: Documentation (see Add-ons section).

<<mousereplace>>

<<mousereplace>>

Triggered by the mouse touching their contents, permanently.

READ: Documentation (see Add-ons section).

<<hoverreplace>>

<<hoverreplace>>

Triggered by the mouse touching the contnet, only temporarily.

READ: Documentation (see Add-ons section).

<<revision>>

<<revision>>

READ: Documentation (see Add-ons section).

<<keyreplace>>

<<keyreplace>>

Triggered by pressing a key.

READ: Documentation (see Add-ons section).

<<timedremove>>

<<timedremove>>

Triggered by time.

READ: Documentation (see Add-ons section).

<<mouseremove>>

<<mouseremove>>

Triggered by the mouse touching their contents, permanently.

READ: Documentation (see Add-ons section).

<<hoverremove>>

<<hoverremove>>

Triggered by the mouse touching the contnet, only temporarily.

READ: Documentation (see Add-ons section).

<<removal>>

<<removal>>

READ: Documentation (see Add-ons section).

<<once>>

<<once>>

Triggered by visiting the passage a certain number of times.

READ: Documentation (see Add-ons section).

<<keyremove>>

<<keyremove>>

Triggered by pressing a key.

READ: Documentation (see Add-ons section).

<<continuelink>>

Triggered by clicking the content.

READ: Documentation (see Add-ons section).

<<timedcontinue>>

<<timedcontinue>>

Triggered by time.

READ: Documentation (see Add-ons section).

<<mousecontinue>>

<<mousecontinue>>

Triggered by the mouse touching their contents, permanently.

READ: Documentation (see Add-ons section).

<<keycontinue>>

<<keycontinue>>

Triggered by pressing a key.

READ: Documentation (see Add-ons section).

<<cycle>>

<<cycle>>

READ: Documentation (see Add-ons section).

<<mousecycle>>

<<mousecycle>>

Triggered by the mouse touching their contents, permanently.

READ: Documentation (see Add-ons section).

<<timedcycle>>

<<timedcycle>>

Triggered by time.

READ: Documentation (see Add-ons section).

<<keycycle>>

<<keycycle>>

Triggered by pressing a key.

READ: Documentation (see Add-ons section).

<<becomes>>

<<becomes>>

READ: Documentation (see Add-ons section).

Notes

A warning about <<hoverreplace>>

As noted by Leon in the v1.1.5 update post, :

One thing that is still not yet fixed is the problem caused when the initial state is larger than the end state. Consider this code:

<<hoverreplace>>[img[large image]]<<gains>>Small text<<endhoverreplace>>

This code is still buggy because as soon as you mouseover the large image, it disappears, leaving the small text behind, and thus your pointer is no longer "over" the hoverreplace structure. I may still be able to fix this in the future, but generally, in this particular situation you should resort to <<mousereplace>>.

SugarCube notes

⚠️ Warning: When passing an optional $variable to the macros which can receive one, you must quote the $variable name (i.e. instead of $variable, use "$variable"). This is required because all macros in SugarCube get $variable substitution automatically, unlike the vanilla story formats where each macro has to perform $variable substitution itself. So, if you don't quote the $variable name, the macro will receive its value instead of its name.

In addition to the internal changes required to make the macro set fully work in SugarCube, additional changes include:

Old Name New Name
<<continue>> <<continuelink>>
<<insert>> <<insertlink>>
<<randomise>> <<randomiselink>>
<<randomize>> <<randomizelink>>
<<replace>> <<replacelink>>
<<revert>> <<revertlink>>
<<revise>> <<reviselink>>

As a minor side benefit of this, these macros are now named consistently with the <<cyclinglink>> macro.

Live demo

Demo Twee code:

:: Start
Replace <<replacelink>>this text<<becomes>>this other text<<becomes>>is over<</replacelink>>. <<hoverreplace>>Hover here!<<becomes>>@@color:red;Hover red!@@<</hoverreplace>>