September 27, 2019
Code to stop timer widget
Comments
(3)
September 27, 2019
Code to stop timer widget
Newbie 2 posts
Followers: 0 people
(3)

I have inserted the timer widget (in countdown mode) in an escape room that I am creating.  I want to stop the timer when the learner has reached a certain slide.  I assume I need to use JavaScript.  Does anyone have the code to do this?  or is there a way to do this without JS?  Thanks!!

3 Comments
2019-10-03 02:59:07
2019-10-03 02:59:07

I don’t use the widgets but I can try to offer some JavaScript and keep it minimal.

One way you might try to tackle this with a JavaScript solution would be to place a little code for the onEnter action where you wish to begin and a little code for the onEnter action of the slide where you wish it to stop.

I tried to make this code as simple as possible.

So you would need two variables. In my example they are  myTimer  and  sec.

The  myTimer  variable houses the interval that runs the timer.
The  sec  variable houses the time in seconds. So let’s say a value of 300 for 5 minutes. You will need to set this either as a default or perhaps as part of the onEnter action as well.

myTimer=setInterval(countdown, 1000);

function countdown() {
sec=sec-1;
}

 

For the exit slide you need to stop the timer.

clearInterval(myTimer);

 

This single line of code will stop the countdown.

The code that starts the interval will basically reduce the value of  the  sec  variable by 1 every 1000 milliseconds or every second.

You will also need a smart shape with  $$sec$$  inside to display the countdown value. Be sure to set this smart shape to be visible for the rest of the project so it is seen on all slides.

If you want to spice this up you could create some little clock images with different states showing 5 minutes, 4 minutes, 3 minutes, etc.

Hopefully this helps.

Like
()
(1)
>
Greg Stager
's comment
2019-10-03 13:18:35
2019-10-03 13:18:35
>
Greg Stager
's comment

Since I al at the Summit in Las Vegas, couldn’t find time to reply more in detail. Thanks for the JS solution, Greg, much appreciated. As usual I would like to post an alternative solution, using the Timer widget and the Timing system variables. At this moment I have too many people to talk with, no time to write.

Like
()
2019-09-28 08:45:12
2019-09-28 08:45:12

I plan a post on timer/hourglass interaction since a while, but didn’t find the time yet.

You do not have access to the code of the timer interaction. You can hide the timer of course. But if you want to save the time for visits to a number of slides, you need to use the timing system variables. I don’t use JS for that, only advanced/shared actions. Have created a lot of similar use cases for clients.  Sorry that the blog is not yet done. Too complicated to answer to a question. You will probably get support from the JS gurus.

Like
()
Add Comment