I currently have a timer that counts down from 10. When it hits 0, I want it to go to a frame labeled done. Unfortunately, this does not work. Here is all of the code on the frame.
stop();
_root.ball.yspeed = 14;//set the ball speed to 14
_root.ball.xspeed = 14;//set the ball speed to 14
_root.cputext = 0;//set cpu score to 0
_root.playertext = 0;//set player score to 0
_root.cpu.speed = _global.cpuspeed;//set cpu speed to that on the button leading into the pong game
_root.timesec = 10;//set time variable to 10
reset();
timerint = setInterval(timer,1000);// I don't know what this is... (perhaps that's where I went wrong?)
function lose (){//define the lose function
_root.cputext ++;//add1 to the cpu score
_root.cputxt = 'CPU: ' + _root.cpu.score;//update the cpu score text
reset();//call the reset function
}
function win (){// the win function, the same as lose buyt for the player
_root.playertext ++;//add1 to the player score
_root.playertxt = 'Player: ' + _root.player.score;//update the score text
reset();//call the reset function
}
function reset(){//define the reset function
_root.ball._x = 261;//move the ball to the center of the x axis
_root.ball._y = 200;//move the ball to the center of the y axis
_root.ball.xspeed = 0;//stop it moving left or right
_root.cpu._x = 225;//reset the paddles to the center
_root.player._x = 255;
}
function timer(){// the timer function is called every second by the set interval call above
_root.timesec--//subtract one to the timesec varible
secs = _root.timesec % 60;//get the seconds by calculating the remainder after dividing by 60
mins = _root.timesec;//mins = total seconds
mins = mins - secs//mins = mins - seconds
mins = mins / 60;//divide by 60 for mins
if(isNaN(mins)) mins = 0;//if less than 1 min it is 0
if(length(mins) == 1) mins = '0' + mins;//padd to 01,02 etc..
if(length(secs) == 1) secs = '0' + secs;//padd to 01,02 etc..
_root.timetxt = mins + ':' + secs//update the text
}
I've tried using;
if(timer>=0){
gotoAndPlay('done');
}
It doesn't work. Please Help me.