Skip to content

"Adding Functionality": SugarCube (v2.18)#


In SugarCube, additional functionality can be added through the Macro.add() function.

In this example, the Date() JavaScript function is used to get the current time. This is saved to payload.contents, and the function is used to convert and append it to the current passage.



Twee Code#

:: StoryTitle
Adding Functionality in SugarCube

:: UserScript[script]
Macro.add("currenttime", {
  tags: null,
  handler: function() {
    // Try the following code and catch any errors
    try {
      // Get the current time and save it to the payload
      this.payload.contents = new Date();

      // Wikify (and append) the current payload contents

    } catch (ex) {
      // Return any errors
      return this.error("Error: " + ex.message);

:: Start

Twee Download