Forum Discussion
Display system time in Storyline 3 using Javascript
A few mistakes in your script. Biggest one is you never call startTime( ); .. thus the script never gets executed. Your timer is set inside the startTime function so also never gets called.
Do try to make a habit of it using either alert("Now im here"); or console.log("and now im here"); to debug your code. If you add calls like this at keypoints in your code its easy to debug and see where and what goes wrong. Without that...its belly-staring.
Another mistake is calling the player 3 times. I am not sure whether it stops your script but it sure aint nice.
Like this the script works:
var player = GetPlayer();
function startTime() { var today = new Date(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds();
// add a zero in front of numbers<10 m = checkTime(m); s = checkTime(s);console.log("m: "+m+" |s: "+s);
player.SetVar("h",h); player.SetVar("m",m); player.SetVar("s",s);
var t = setTimeout(function(){ startTime() }, 1000);}
function checkTime(i) { if (i < 10) { i = "0" + i; } return i;}
startTime();
For your ease adding a working 360 and Storyline 3 version.
Kind regards,
Math Notermans