I have some JavaScript running in Storyline and...

Hi folks,

My code is updating some main variables called Countdown_Duration, Countdown_Finished, Randy and RunFull.

The function for the first part starts and stops a countdown.

In the second part with Randy a random layer is being set to visible there is 10 in all.

The code works fine but for some reason and quite randomly, the browser freezes up and requires a refresh.  Can anybody see anything here that looks like it would do something like that?

/////////////////////////////////////////////////////

var fin="Done";
var player = GetPlayer();

var seconds, totalTime;
var counter = setInterval(timer, 1000);
var finished = player.GetVar("fiN1");
var count = player.GetVar("Countdown_Duration");
var JF1 = player.GetVar("F1");
var JF2 = player.GetVar("F2");
var JF3 = player.GetVar("F3");
var JF4 = player.GetVar("F4");
var JF5 = player.GetVar("F5");
var JF6 = player.GetVar("F6");
var JF7 = player.GetVar("F7");
var JF8 = player.GetVar("F8");
var JF9 = player.GetVar("F9");
var JF10 = player.GetVar("F10");
var JF11 = player.GetVar("F11");
var All = [ JF11, JF1, JF2, JF3, JF4, JF5, JF6, JF7, JF8, JF9, JF10 ];

function zeros(i) {
if (i < 7) {
i = "0" + i;
}
return i;
}


function timer() {
count = count - 1;
finished = player.GetVar("fiN1");
seconds = zeros(count % 60);
if (count === 0){
player.SetVar("Countdown_Finished",fin);
return;
}
if (count < 0) {
clearInterval(counter);
return;
}
if (finished == 1) {
clearInterval(counter);
return;
}
totalTime = seconds;
player.SetVar("CD",totalTime);
MatH();
return;

}

function MatH(){
var rNB09 = Math.floor(Math.random() * 10);
var tester = All[rNB09];
var i = 0;
if (tester == 1){
for (i = 0; 0 < 10; i++) {
var Poz = All[i];
if (Poz === 0){
player.SetVar("Randy",i);
player.SetVar("Gotin",1);
}
}
}
else{
player.SetVar("Randy",rNB09);
player.SetVar("Gotin",2);
}
player.SetVar("RunFull",0);
}

 

4 Replies
Erin Flage

Do you have the published output that can be viewed?  It's hard to troubleshoot without being able to see the output.

What browser are you using?

Have you looked at the Developer tools/console to see if any errors are being reported?

Off the top of my head, I'd guess there's some type of infinite loop that is causing the freeze up.

Luke ODonnell

Hi Guys,

Yes I figured this out. I forgot to put in a return; in the JavaScript. in these

if (tester == 1){
for (i = 0; 0 < 10; i++) {
var Poz = All[i];
if (Poz === 0){
player.SetVar("Randy",i);
player.SetVar("Gotin",1);
}

It was testing to see if a condition was true elsewhere in my code. Without the return it just kept doing the check and that was crashing my project.

Thanks to all who tried to help.

Luke