Creating a stopwatch/timer

Hi,

I am working on creating a video that I will most likely insert into Storyline2. I need to have a stopwatch begin at a certain point and then stop at a certain point so that people who are viewing the video know that at 2 minutes into the scenario this happened, 10 minutes in this happened and so on.

So, my question...how can I built such a stopwatch/timer????

6 Replies
Alexandros Anoyatis

Hi Rhona,

Short answer is "Yes you can". Here's how:

1) Create a number variable, say timer
2) Create a JS trigger at the time you want the timer to start and add the following code:

var player = GetPlayer();
var myVar=setInterval(function () {myTimer()}, 1000);

function myTimer() {
var s = player.GetVar("timer");
++s;
player.SetVar("timer",s);
}

This will initialize a function that adds 1 to timer every 1 second

3) Add necessary triggers to stop the timeline (or show/record whatever it is you want) when timer equals 120 and another when timer equals 600.

There's more you can/should do depending on the exact functionality you're going for which isn't really clear from your description.

Hope this helps,
Alex

Daniel Mitchell

Alexandros, I would love to see your example in a story file. I've tried to re-create, but I'm not sure what I'm doing wrong. It probably comes down to my very limited experience with JS, but on the off-chance that I'm just doing something wrong in SL2, I'd really like to learn the technique.