JavaScript Countdown Timer created in SL II

Here is my version of a countdown timer using JavaScript. I've included a few input fields for minutes and seconds but I think in most cases, these would be hard coded.  

I chose to use input fields for this demo to provide a little transparency into how this works.

What I like about a JS solution is that if the timer is on a master slide, it is persistent across layers and/or slides (as shown in the file).

5 Replies
Matthew Bibby

Good work Owen. 

One issue (that I only thought to look for, because I have the same problem with my timer) is that if the user hits start multiple times you end up with something like this:

So I just disable the start timer button once it has been pressed once to avoid, but there are probably better ways to handle this. 



Actually Matthew, I was aware of that behavior. :-) 
I was putting this together for a client where the time would be hard coded and the starting trigger is not a button so it is a non- issue. I exposed it as buttons in this file so community members could see the separate start and stop scripting/variables/etc that they could tie to their start and stop triggering behaviors.

If using buttons, you would need to change the button to a selected state as you indicated or "disable the javascript from re-running. Additionally, if using buttons AND displaying across multiple slides/scenes, you would also need a "IsRunning" SL variable to control the state of the button on subsequent slides else it will default to normal on those slides.

(I admit to being a little lazy here just to get this posted before leaving the office yesterday.... Forgive me? :p)