Stop and Reset Timeout Function When Button Is Clicked.

So, I have a Timeout function that takes from passage A (the one that I am currently in) to passage B. But, if I have a button in passage A to go to passage C, things will get funky. If the button is clicked, it will take me to passage C, but also redirect me to passage B the Timeout function runs out.

This will be useful for skipping timed cutscenes and other nifty tricks. Can anyone help me out with this? Thanks :)

Broadwaydude


Are these sections, or passages?
If they're sections, you can just have the timeout function check which section the player is in, and do nothing if they've already gone somewhere else.

If you're using passages, I don't think there's an easy way to check (as the _section attribute only gives the name of the current section).
To clear a timeout, you need to get the return value of the setTimeout function, which is an ID number. You can pass this number to clearTimeout to cancel the timeout.

For example:

[A]:
    var timer = window.setTimeout(function() { squiffy.story.passage('B'); }, 5000);
    squiffy.set("timerID", timer);

Do you want to go to [C]?
Timeout with ID {timerID} is running!

[B]:
Five seconds and you didn't go to [C] yet?

[C]:
    window.clearTimeout(squiffy.get("timerID"));

Hi! There's no timeout now.

@mrangel, a true lifesaver as always.

Could you show me an example of how to do this with sections as well?

Thank you so much!


With sections, the simple way:

[[A]]:
    window.setTimeout(function() { 
        if (squiffy.get('_section') == 'A') {
            squiffy.story.go('B');
        }
    }, 5000);

Do you want to go to [[C]]?

[[B]]:
Five seconds and you didn't go to [[C]] yet?

[[C]]:
Hi! You're here!

Or using the same method as the example above:

[[A]]:
    var timer = window.setTimeout(function() { squiffy.story.go('B'); }, 5000);
    squiffy.set("timerID", timer);

Do you want to go to [[C]]?
Timeout with ID {timerID} is running!

[[B]]:
Five seconds and you didn't go to [[C]] yet?

[[C]]:
    window.clearTimeout(squiffy.get("timerID"));

Hi! There's no timeout now.

Now, if I somehow wind up back in A, how can I disable the timer for the next time I'm in section A?

Let's say this section is a room. Upon entering I trigger a time bomb. If I disable it, leave the room, and visit the room again, I don't want that time bomb to restart. I already disabled it.

Thank you so much for helping me out!


Log in to post a reply.

Support

Forums