Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Javascript help needed to modify macro

I need a timer which starts and runs in any passages until it runs out (sending the user to the death passage) or until the user does the right thing to stop it. I modified <<timedgoto>> macro, adding a "globtimedgoto" to work in any passage:
{function cssTimeUnit(s)
{if(typeof s=="string"){if(s.slice(-2).toLowerCase()=="ms"){return +(s.slice(0,-2))||0}else{if(s.slice(-1).toLowerCase()=="s"){return +(s.slice(0,-1))*1000||0}}}throwError(a,s+" isn't a CSS time unit");return 0}
var t,d,m,s;
It works. Now I need to stop it. I know I should call clearTimeout(ID), but how to get this ID ('macros["goto"].timer') from the script to Twine variable and how to make this call later? This is a very simple question - I just don't know Javascript and its using with Twine well enough.


  • Well, I simplified everything as much as possible and came to this code:
    <<set $globaltimedgoto=
    {return setTimeout(state.display(p),t)}
    <<set $timer=$globaltimedgoto("timeover",210000)>>
    It goes to "timeover" passage, but immediately (the link "Hello" never appears), ignoring the time value! Even replacing "t" variable with a constant 210000 doesn't help. What's wrong?
  • Nobody helped. but I found a solution myself:
    <<set $globaltimedgoto=
    {return setTimeout(function(){state.display(p)},t)}
    This works.
Sign In or Register to comment.