Help with some Javascript function instance

Hi All,

This may drive some people bananas. I am running a JavaScript function that changes a variable CD which shows a countdown  on a watch. Its for a game that has the learner trying to find mistakes with in the given time. If they get it wrong or right they jump out to anther screen where the countdown is reset. When they return the timer is reset but another instance of the function is still running in the background. I need a way to destroy / delete the function before the next round starts.

here is the java script.

var fin="Done";
var player = GetPlayer();
var count = player.GetVar("Countdown_Duration");
var totalTime = 0;
var seconds;
var counter = setInterval(timer, 1000);
var finished = player.GetVar("fiN1");


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

 

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

I am clearing all the variables on another slide like this.

seconds = null;
totalTime = null;
counter = null;
count = null;
finished = null;
JF1 = null;
JF2 = null;
JF3 = null;
JF4 = null;
JF5 = null;
JF6 = null;
JF7 = null;
JF8 = null;
JF9 = null;
JF10 = null;
JF11 = null;
All = null;
totalTime = null;
clearInterval(counter);
var player = GetPlayer();
player.SetVar("CD".null);

Thanks

Luke

 

Be the first to reply