ChapelR / custom-macros-for-sugarcube-2

A collection of systems and macros for Twine.
https://macros.twinelab.net/
The Unlicense
166 stars 44 forks source link

Suggestion for <<done>> #16

Closed tmedwards closed 6 years ago

tmedwards commented 6 years ago

To avoid the duplicate task ID issue, have you thought of doing something like the following?

(function () {

    var taskCount = 1;

    Macro.add('done', {
        skipArgs : true,
        tags : null,
        handler : function () {
            var wikiCode = this.payload[0].contents.trim();

            // bail out if no payload
            if (wikiCode === '') {
                return;
            }

            // register the task
            postdisplay[':chapel-done-macro-' + taskCount] = function (task) {
                delete postdisplay[task]; // single use
                $.wiki(wikiCode); // wikify the source code
            };

            // increment the task ID counter
            taskCount++;
        }
    });

})();

EDIT: Added the skipArgs property.

ChapelR commented 6 years ago

That is a much better idea than caching it. Thank you.

tmedwards commented 6 years ago

Also, just thought of this. Since you're not doing anything with the arguments, you may as well disable argument processing via skipArgs. For example:

    Macro.add('done', {
        skipArgs : true,
        tags : null,
        handler : function () {