Add-ons / Continue Macro Set

Used to create basic "press any key" or "click anywhere to continue" style interactions.

Author ChapelR
Website https://twinelab.net/custom-macros-for-sugarcube-2/#/continue-macro
Story format SugarCube 2
Last checked Sun Mar 29 2020
License Unlicense
Download continue.zip

Index

Overview

Used to create basic "press any key" or "click anywhere to continue" style interactions. You can nest <<cont>> macros to create chains of such interactions, too. Something I see requested frequently, but had to sit down and really dwell on to develop a decent implementation that doesn't break other interactions or generally suck.

Macros

<<cont>>

<<cont>>

Syntax: <<cont [keywords]>>...<</cont>>

This macro waits for user input before evaluating its contents, and can be used to create situations where the user can click anywhere, or press any key (with the right keywords), to continue.

Arguments:

Usage:

/* click anywhere to go to the next passage */
<<cont>><<goto 'Next'>><</cont>>

/* click anywhere or press any key to continue */
You slowly turn around...
<<cont append keypress>>The ghost is behind you!<</cont>>

/* nest <<cont>> macros to create text you can "advance" through,
   like so */
@@#exposition;
Many years ago, the knights of the round table were gathered in
opposition to the witch Morgan La Fey.
@@

<<silently>>
    <<cont keypress>>
        <<replace '#exposition'>>\
            However, all but King Arthur fell in the ensuing battle.\
        <</replace>>
        <<cont keypress>>
            <<replace '#exposition'>>\
                King Arthur swore revenge, and set out from his castle!\
            <</replace>>
        <</cont>>
    <</cont>>
<</silently>>

<<ignore>>

<<ignore>>

Syntax: <<ignore selectorList>>

By default clicks on any link or button elements or any elements with therole="button" attribute, and clicks on dialogs or the sidebar will not trigger the <<cont>> macro. Additionally, any element with the class continue-macro-ignore will also be ignored. You can use this macro to add more selectors to the ignore list. Note that this macro can only be triggered before the story starts—for example, from the StoryInit special passage.

Arguments:

Usage:

/* ignore <i> elements */
<<ignore 'i'>>

/* ignore elements with the classes 'click' or 'hello' */
<<ignore '.click' '.hello'>>

JavaScript API

setup.cont()

setup.cont()

Syntax: cont(keypress, callback) or setup.cont(keypress, callback)

The cont() function can be used to create a similar effect to the continue macro from JavaScript.

Arguments:

setup.cont.ignore()

setup.cont.ignore()

Syntax: cont.ignore(selectorList) or setup.cont.ignore(selectorList)

Adds to the ignore list just like <<ignore>>. Must be used before the story starts.

Arguments:

setup.cont.reset()

setup.cont.reset()

Syntax: cont.reset(selectorList) or setup.cont.reset(selectorList)

This function removes all current continue event handlers, and can be used to add to the ignore list if supplied with appropriate arguments.

Arguments:

Live demo

Demo Twee code:

:: Start
This demo is in a [[separate passage|Continue Example]] to avoid triggering it accidentally.