How to create timers in a gamebook

RoyalRB
09 Feb 2020, 21:44I'm trying to make a simple timer that does the following:
-On entering a page, the timer will be activated. Let's say 10 seconds.
-When the timer ends, the player will be sent to another page, where the timer could be set and activated again.
-The timer should be flexible in the amount of seconds. This means page 1 could have 10 seconds, then page 2 could have 5 seconds.
I tried importing the timer library, but I don't really understand how it works. Could someone explain me how to achieve this kind of timer result?
mrangel
09 Feb 2020, 22:37I'm not entirely sure; I believe there were some issues with timers in gamebook mode, but I'm not sure of the details.
However, there's nothing to stop you using javascript timers:
JS.eval("setTimeout( function() { sendCommand('page12'); }, 5000);")
Will send the player to page12 after 5 seconds (times are in milliseconds)
If you want to be able to cancel it, that might be a little more work. Something like:
JS.eval ("window.timedPage = setTimeout( function() { sendCommand('page12'); }, 5000);")
to set a timeout, and
JS.eval("if (window.timedPage) { clearTimeout (window.timedPage); }")
to cancel the one from the previous page. So if you have multiple pages that set a timer, you'd want each of them to cancel the one from the previous page before setting its own.
Note that in gamebook mode, if the current page has a link to the page the timeout is sending you to, it may print the text of that link as if the player had clicked on it.