I’ve been making a game that includes a timer, and now I running into a problem. The timer works - it counts down to zero, and then when it reaches zero, it goes to a different scene and determines whether or not the player has enough points to pass the level. However, If you retry the level, the timer goes by twice as fast when the level plays again - which I’m pretty sure means that the timer is continuing. I need to figure out how to stop the timer right when it reaches zero… Here’s my code so far, which I have in the first frame of my scene:
stop();
timer = 30;
function wait() {
timer--;
if (timer == 0) {
gotoAndPlay("lvl1-score",1);
}
}
myTimer = setInterval(wait, 1000);
explained:
. line 1: stops the movie
. line 2: sets the starting value for the timer
. line 3: defines the function ‘wait’
. line 4: tells the timer to countdown
. line 5: defines what is to happen when the timer reaches ‘0’
. line 6: tells the movie to go to a different scene and frame
. line 7: sets the ‘interval’ on the timer so that it counts one second at a time
Does anyone know what I should add that will stop the timer at zero ?