# End time limit in game

**URL:** <https://forum.kirupa.com/t/end-time-limit-in-game/135073>\
**Category:** Uncategorized\
**Created:** [January 24, 2005, 3:39pm UTC](https://forum.kirupa.com/t/end-time-limit-in-game/135073 "2005-01-24T15:39:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emspott](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@emspott](https://forum.kirupa.com/u/emspott)\
**Post date:** [January 24, 2005, 3:39pm UTC](https://forum.kirupa.com/t/end-time-limit-in-game/135073/1 "2005-01-24T15:39:44Z")

</div>

I am trying to make my timer stop at 10 seconds.  
Then game will go to ‘game over’ -  
can anyone assist in the proper code to implement the gameover at 10 seconds?  
I Think it is somewhere in my timer code…  
Thank you in advance!

Here is the timer code:  
\_root.onEnterFrame = function() {  
if(\_root.gameIsRunning) {  
if(getTimer() \> \_root.startTime + \_root.secondsCounter + 1000) {  
\_root.secondsCounter += 1000;  
\_root.setTimeDisplay();  
}  
if(\_root.gameIsOver.gotoandplay(“gameover”)) {  
if(getTimer() \> \_root.startTime + \_root.secondsCounter + 1000) {  
\_root.secondsCounter += 1000;  
\_root.setTimeDisplay();  
\_root.gameTime = 10 \* 1000;  
}  
if(\_root.showCards) {  
if(\_root.showTimer == 0) {  
\_root.showTimer = getTimer();  
}  
else {  
if(getTimer() - \_root.showTimer \>= 1800 - \_root.gameLevel \* 200) {  
\_root.showTimer = 0;  
\_root.showCards = false;  
\_root.arrCats[selCat1].\_visible = false;  
\_root.arrCats[selCat2].\_visible = false;  
\_root.arrCards[selCard1].\_visible = true;  
\_root.arrCards[selCard2].\_visible = true;  
\_root.selCat1 = -1;  
\_root.selCat2 = -1;  
\_root.selCard1 = -1;  
\_root.selCard2 = -1;  
}  
}  
}  
}  
}  
};

Here is the main game code:  
if(!isNotFirstStart) {  
createArrays();  
initGame();  
getInitialPosition();  
initSharedObject();  
loadHighscore();  
};  
updateGUI();

// Global variables  
function initGame() {  
gameIsRunning = false; // True if game is running, otherwise false  
gameIsOver = false; // True if game is over, otherwise false  
gameLevel = 4; // Initial speed level  
startTime = 0; // Time of starting game  
gameTime = 10 \* 1000; //end time of game  
secondsCounter = 0; // Count seconds of playing game  
attemptsCounter = 0; // Count attempts  
matchesCounter = 0; // Count matches  
gamePoints = 0; // Score  
selCat1 = -1; // Index of firt cat picture  
selCat2 = -1; // Index of second cat picture  
selCard1 = -1; // Index of firt card  
selCard2 = -1; // Index of second card  
showCards = false; // Show selected cards until timeout is over  
showTimer = 0; // Timer for showing two cards  
isNotFirstStart = true; // Flag to say that game started first  
phpCounter = 0; // Dummy dummy, appended to highscore URL to outwit the browser cache  
modeHighscore = 0; // 0=Shared Object, 1=PHP  
if(\_level0.highscoremode == “php”) {  
modeHighscore = 1; // URL memory.swf?highscoremode=php  
}  
};

// Time display  
function setTimeDisplay() {  
var s = String(Math.round(\_root.secondsCounter / 1000));  
while(s.length \< 4) {  
s = " " + s;  
}

```
var a = s.charAt(3) * 1;
for(var i = 0; i &lt; 10; i++) {
	arrT0*._visible = (i == a);
}
var b = s.charAt(2) * 1;
for(var i = 0; i &lt; 10; i++) {
	arrT1*._visible = (i == b);
}
var c = s.charAt(1) * 1;
for(var i = 0; i &lt; 10; i++) {
	arrT2*._visible = (i == c);
}
var d = s.charAt(0) * 1;
for(var i = 0; i &lt; 10; i++) {
	arrT3*._visible = (i == d);
}	

```

};
