0 votes
asked by (420 points)
edited by

So for the <<timed>> macro in sugarcube2:

→ Replace some text after 10 seconds

I like green <span id="eggs">eggs</span> and ham!\
<<timed 10s>><<replace "#eggs">>pancakes<</replace>><</timed>>


Is it possible to use a variable for the x seconds?

So for example, if I want to do this: <<set $sec= $min*60>> and then use <<timed $secs>>...<</timed>>


Thank you!

1 Answer

0 votes
answered by (58.8k points)
edited by

As the <<timed>> macro's documentation clearly states it only accepts CSS time values, which must include a bundled unit (e.g. ms and s).  Thus, you may not simply use an integer, no.

What you can do is to add the appropriate unit to either the value stored within the variable or at the macro invocation via a backquote expression.

Example using a temporary variable to hold the CSS time value:

<<set _delay to (_min * 60) + 's'>>
…
<<timed _delay>> … <</timed>>

Example using a backquote expression to create the CSS time value at the macro invocation:

<<timed `(_min * 60) + 's'`>> … <</timed>>

 

PS: Unless you're using the time values in other passages, you should probably be using temporary variables rather than story variables, as the former do not become part of the history.

commented by (420 points)
This works, thanks!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...