Forum Discussion
Create a Timer for Storyline Any Version
I have done a lot of research over the last few years on creating a timer that can count down or up on a slide or even a project. Since what I wanted was something at the slide level for activities or games, I wanted something simple that I could replicate.
I started with this article in the community by Paul Alders Timer to use in Storyline. This led me in several directions including the article by Swift Elearning Services. This last article is very comprehensive, but it was a lot more than what I wanted. It is a great idea for a timer that does hours, minutes, and seconds. You can also use the Quiz timer in Storyline.
I had also taken a course (on Udemy) from Alexander Salas where he used images on layers and had them appear with triggers and variables. That process works with multiple layers but was not as simple as I wanted.
I realized I wanted a process that would work on only one slide and one or two layers. It would probably also use variables. At first, I decided to use the multiple layer process putting a number on each layer that appears on the base layer as the slide runs. Each layer was only one second so I started with 5 as a test. What I liked about this approach is I only used triggers to show each layer.
First Timer Attempt
To start, I added the five layers with the numbers from five to one and set the first trigger to show the layer for 5 when the timeline reached a cue point.
I put two triggers on each layer, one that hides the layer and then shows the next layer when the timeline ends.
I liked the way this worked because it was simple and I could just copy this setup to other slides so they could have a timer as well.
Second Attempt
I then tried to put all of the numbers that count down all on one layer. I added ten text boxes each one second long to the layer as I saw in one of the examples.
I added a trigger to start the layer when the timeline starts and then show an ending layer when the timeline ends. Again, this is simple and it can be copied to other slides.
Third Attempt uses a Variable
I liked the approach from Swift Elearning Services using a variable to count the time. I created a layer and set it for one second. I created a variable titled Timer_Down. I set a trigger to Show Layer with the timer when the timeline starts.
The triggers on the loop layer are the most important. One trigger subtracts a number each time the timeline starts. Another trigger hides the layer, the another trigger shows the layer and finally a trigger shows an ending layer when the count down reaches zero.
I had this idea from Jeff Kortenbosch’s video on how to create a looping animation. It made sense to me that looping the layer would do the same thing for the count down and it did.
As with the first two attempts, I liked the simple way this works and I can extend it for longer times or shorter times by setting the triggers.
If you want to download an example of all three, click Storyline File.
- NancyWoinoskiSuper Hero
I use the following JavaScript for simple countdown timers. In this example the counter counts down from 10 seconds. If you want to change the countdown duration, you simply change the var t value. Note the time is expressed in milliseconds so if you wanted to change the countdown to 1 minute, y var t would = 60000
In Storyline you have to create text variables for hours, minutes and seconds and set the default values. So for the 10 second example, you would set the variables as follows:
hour= 00
minutes = 0
seconds = 10
On the slides that you want to count down to display, you would add a text box with
%hours%:%minutes%:%seconds%
I have attached a Storyline 360 example so you can see this in action.
Below is the JavaScript
-----------------------------------------------------------------------------------------------
var player = GetPlayer();
var t = 10000; //Time in Milliseconds eg. 10 seconds = 10000function getTimeRemaining(endtime)
{
t = t - 1000;
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
return {
'total': t,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}function initializeClock(id, endtime)
{
function updateClock()
{
if(player.GetVar("pause") == 0)
{
var t = getTimeRemaining(endtime);
player.SetVar("hours",('0' + t.hours).slice(-2));
player.SetVar("minutes",('0' + t.minutes).slice(-2));
player.SetVar("seconds",('0' + t.seconds).slice(-2));
if (t.total <= 0)
{
clearInterval(timeinterval);
}
}
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}var deadline = new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
initializeClock('clockdiv', deadline);- MelissaSurezdelCommunity Member
Hello Nancy,
Thanks a lot for this sample. Could you let me know how to display milliseconds? Newbie here, trying to figure out how to use this code.
Thanks a lot!
- MichaelHinzeCommunity Member
Just for completeness, there is another option which doesn't require layers or staggered objects on the timeline. It uses an offtstage looping animation, see the first example here.
- JeffreyRileyCommunity Member
Thanks for adding your example. It is always amazing to see how many ways
Storyline can solve a problem. - JeffreyRileyCommunity Member
I like it. Alexander Salas uses a similar object and uses a trigger to count the motion. You must be using the same concept. Your timer image is very well done. For a game or activity I would not use something that large but I like what you have done.
- ThorstenHoltCommunity Member
Dear Michael, your solution seems to be very lean and efficient. Could you explain it further or have a SL-file by hand for me? I dont want to create a timer with Javascript, just want to keep it simple.
- JeffreyRileyCommunity Member
Thorsten, If you go to the top of this post, my version is very simple and does not need javascript at all. If you need to have a timer that covers hours, minutes, and seconds then you do need the javascript. If you need anything in seconds, my version works well and is easy to change.
I also include a template you can download.
- anoyatisCommunity Member
All of the above approaches are functional, no doubt, but not nearly as precise - any slowdowns or frameskips do not count against the timer, time required to load the new slide is not taken into account etc.
They work fairly well for short timing interactions (0 to 10 seconds) but become inaccurate for larger ones (like 1, 2, or 15 minute timers, or even longer). For that you will need to resort to Javascript, using the setInterval methodJust my 2c,
Alex - JeffreyRileyCommunity Member
Alex,
My intention was to just time short interactions of maybe 20 or 30 seconds. I would use one of the other methods for something longer.
These are very simple to use and will help people who don't have the javascript skills you mention.
Sometimes, the simple way is all we need.
- JeffreyRileyCommunity Member
Nancy,
Thanks for adding your ideas and for sharing the javascript and storyline file. The great part of this community is the way people share their ideas.
Storyline is so flexible and this example shows how many ways there can be to solve the same problem.
- PL3Community Member
Thanks for the sample Nancy.
I'm just starting to dabble with javascript. Right now, when I work with it, the timer continues where it left off on the previous slide even though I have javascript included on each slide.
Do you know how to alter the code so that it restarts at "10" on each slide?
I appreciate your help.
Thanks again,
PL
- NancyWoinoskiSuper Hero
Hi PL, for each slide that has the timer you have to reset the hour, minutes, and second variables in Storyline back to 0, 0, and 10 respectively when the timeline starts.
- KennethgGoeiemaCommunity Member
Nancy, you are a life saver!
Just one thing I would like to find out. I am using the .js your shared and it worked great. But I have 3 quizzes and would like to know how you reset the time. Cause it just continues counting down from the previous .js
- ZsoltOlahSuper Hero
Here's some simple timer function as well. Check out idea #2
https://www.rabbitoreg.com/examples/p99/#/lessons/h9N-9wO3BF1Ly8KVd-531fT7Q_8Som_e
- PL3Community Member
Thanks Nancy for your help above. I couldn't get that to work, so I created a separate instances of the "Pause" variable for each slide. That did the trick; the timer starts on "0" on each slide now.
I'm sure it's not the best way to do. But I got it working.
Thanks again for sharing and replying - it's greatly appreciated!
PL
- NancyWoinoskiSuper Hero
Hi PL, if it works, it is the best way to do it. Glad you got it to work.
- MarkAnthonyChesCommunity Member
I know this is an old post, but hello to all the heroes!
I have built a simple time loop timer, but if I place it on a slide with other layers it stops counting when a different layer is visited...
Can anyone help?
- SarahHodgeFormer Staff
Hey MarkAnthony! If you click on the layer and then the slide properties gear icon, you can then uncheck "Hide other slide layers" and that should do the trick. Here's a screenshot for reference:
- MarkAnthonyChesCommunity Member
Thank you Sarah!
I'll check it out soon.
Can I ask you for other advice if needed :)
I'll get back with my results.
Thanks again!