Skip to content

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

Summary#

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 jQuery.wiki() function is used to convert and append it to the current passage.

Example#

Download

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
      jQuery(this.output).wiki(this.payload.contents);

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

:: Start
<<currenttime>><</currenttime>>

Twee Download