Revision of Twine: <<timedgoto>>, a simple timer from Tue, 03/05/2013 - 00:45

This is inspired by the Timer script used in Panic! by Astrid Bin and Stefano Russo. That script implements a sophisticated timer entity which can count down throughout the entire game, can draw itself in graph form in a canvas element, and can be paused and resumed. However, it requires multiple macros to set it up for each use, and it can be a bit cumbersome if you simply want the game to advance to a new passage after a delay.

I felt like writing a similar macro that would be shorter and more specific. This one, <<timedgoto>>, just automatically (and invisibly) goes to the given passage after the given number of half-seconds have passed. Each use of the macro only functions within the passage that uses it - if you're using Sugarcane or single-passage Jonah and leave the passage by a normal link, it will be disengaged.

version.extensions.timedgotoMacro={major:1,minor:0,revision:0};macros["timedgoto"]={timer:null,handler:function(a,b,c,d){var t=c[c.length-1];
var d=d.fullArgs();d=d.slice(0,d.lastIndexOf(t));d=eval(Wikifier.parse(d));if(d+""){if(this.timer){clearTimeout(this.timer);
}var s=state.history[0].passage.title;this.timer=setTimeout(function(){if(state.history[0].passage.title==s){state.display(d,a);
}},(parseInt(t)||0)*500);}}};

Usage examples:
* <<timedgoto "underwater" 5 >> goes to the "underwater" passage after 2 and 1/2 seconds if you stay in this passage.
* <<timedgoto $deathpassage 10 >> goes to the passage whose name is in the $deathpassage variable after 5 seconds.

Notes:
* This technically uses code parameters (that is, it accepts "strings", $variables, and "various"+$combinations of both, and its parameters are interpreted as Javascript), except that the final parameter (the time value) is separated from the rest and interpreted as a literal parameter.
* If the time value is 0 or not a number, it will trigger instantly.

pensive-mosquitoes