A code that allows timer function to stop after making a decision

LA-Laker
04 Aug 2017, 22:44

Hello, this is La-Laker. I want to thank manowar for this code.

[[Link-01]]:
setTimeout(function(){ squiffy.story.go("Link-02"); }, 5000);
After 5 secs will automatically take you to Link 02
[[Link-02]]:
Your time is up.

But, I need more help. What is the proper code for the timer function to cease after picking a selection?

[[Link-01]]:
setTimeout(function(){ squiffy.story.go("Link-02"); }, 5000);
After 5 secs will automatically take you to Link 02

[[Decision A]]
[[Decision B]]

[[Link-02]]:
Your time is up.


Siddone
11 Aug 2017, 21:01

It's exactly the same question I wanted to ask. It would double the chances to use the timer in the most effective way. I hope someone has an answer.


K.V.
11 Aug 2017, 21:58

Hello,

I've been trying to find out how to do this, as well.

Then, I saw this thread, and I found this:

https://www.w3schools.com/Jsref/met_win_cleartimeout.asp

Which helped me learn to do this:

@title clear_timeout

[[Link-01]]:
    squiffy.myVar = setTimeout(function(){ squiffy.story.go("Link-02"); }, 5000);
    setTimeout(squiffy.myVar);
    
After 5 secs will automatically take you to Link 02

[[DECISION 1]](Link-02)

[[DECISION 2]](Link-03)

[[Link-02]]:
    clearTimeout(squiffy.myVar);
    
Your time is up.


[[Link-03]]:
    clearTimeout(squiffy.myVar);


I made this one up for this example.

Enjoy!


LA-Laker
15 Aug 2017, 04:51

Thanks, K.V. That helps a lot! I'll give this code a shot.


K.V.
15 Aug 2017, 06:28

Thanks, K.V. That helps a lot! I'll give this code a shot.

👍 KV likes this.


You're welcome! It's no problem!