Using Javascript to Gamify a Countdown Timer (incorrect answers subtract time)
Hi all,
Appreciate your help looking into this. What I am trying to do is gamify an activty where there is a countdown where the learner has to type in the correct response before the time runs out AND there is consequences to writing incorrect answers by subtracting the time.
I have the timer all set up with no issues via Javascript. Since the variable timer is updated via a trigger, the Javascript needs to also have a function that retrieves the existing value of the variable timer because, it sets the value of the variable timer based on the internal variable "sec". Since "sec" isn't affected by the update of the variable timer via the trigger on the incorrect layer, it won't retrieve it and will just continue with the count based on sec.
How can I modify the variable so Javascript subtracts from the time and then continues counting down?
Here is the code for the timer:
//Getting the player
const player = GetPlayer();
//Where to start
let sec = 60;
//Set up the timer
function startTimer(){
sec -= 1;
player.SetVar("timer",sec);
if (sec == 0) {
clearInterval(timerId);
}
}
//Start the timer
timerId=setInterval(startTimer,1000);
*While there are ways to do it via the timeline & master slides/layers, if you have different layers it messes with the timer so I need a Javascript solution