Need Some Help to Create Stop watch in storyline 360 with JavaScript

Apr 29, 2023

Hi guys,

can you help me to create stopwatch.
here is the code written but am not getting it properly.
can any one respond where went wrong in the code.

var player=GetPlayer();

var mseconds = player.GetVar("MSeconds");
var seconds = player.GetVar("Seconds");
var minutes = player.GetVar("Minutes");
var hours = player.GetVar("hours");



mseconds = 1000
  if(mseconds == 1000){
    seconds = seconds + 1
    mseconds = 0;
      if(seconds == 60){
      minutes = minute + 1
      seconds = 0;
        if(minutes == 60){
        hours = hours + 1
        minutes = 0;
      }
    }
  }
player.SetVar("MSeconds",mseconds);
player.SetVar("Seconds",seconds);
player.SetVar("Minutes",minutes);
player.SetVar("Hours",hours);


Thanks in advance 

 

7 Replies
Math Notermans

Although this is far from complete, here are some fixes to help you get started.

- You need to check your variables. The NaN is caused by setting hours instead of Hours.
Do use consequent variable naming all the time. I use camelCasing... So instead of Hours i would name it stopwatchHours or swHours to be sure i get the proper var.

- Now the script is onlt executed at Storyline start. You need it to loop. I added a SlideLayer that loops in it. Quickly fixed it... can be improved.

Math Notermans

Ofcourse you can make a loop in Javascript only, but thats more complex. Mainly due to scope issues Storyline will cause.

https://www.programiz.com/javascript/for-loop

Here you find a lot of ways to create a loop in Javascript...easy enough... but as said Storyline scope issues make it more difficult, so you are better off using a SlideLayer loop.