How to stop a <<timed>> macro without leaving or reloading the passage?

Hello all!

In SugarCube 2.30.0 is there a way to stop in progress <<timed>> macros other than leaving a passage or reloading it?

If you could make an <<audio>> macro trigger something other than goto when it finishes, then stopping the <<audio>> would be an option I suppose.


Not really. If you need to do that, then you could use a setTimeout() function instead, and then call the clearTimeout() function on the value returned by setTimeout() when you need to cancel the timeout. For example:

<<button "Start Timeout">>
	<<set _timeoutID = setTimeout( function () { alert("10 Second Timeout"); }, 10000)>>
<<button "Cancel">>
	<<run clearTimeout(_timeoutID)>>

That will show a message 10 seconds after the “Start Timeout” button, unless you hit the “Cancel” button before it appears.

Just make sure you cancel the timeout before exiting the passage, if needed, otherwise it may trigger when in the next passage.

You can use $.wiki("SugarCube code here") to trigger macros from within that function instead.

Hope that helps! :slight_smile:

Plugged it in, went like clockwork! I’ll be using this a lot probably. :laughing:
Thanks for the help!