"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.

Live Example

Download: Live Example

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>>

Download: Twee Code

results matching ""

    No results matching ""