# How do i create a game timer?

**URL:** <https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139>\
**Category:** flash\
**Created:** [October 3, 2004, 3:33am UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139 "2004-10-03T03:33:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://forum.kirupa.com/u/Dave)\
**Post date:** [October 3, 2004, 3:33am UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/1 "2004-10-03T03:33:02Z")

</div>

hey guys! I have already looked for a tut here and other places and i still can’t find what im after.

Im creating a game when they **start the game a timer begins** , when they finish the game, the timer stops and **the time is displayed in minutes and seconds** it took to complete the game.

I don’t this is very hard but i cant get it to work. I’ve tried the get Timer function but i was unsuccessful. Can someone please help me?

Thanks guys.

🐇

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 3, 2004, 8:21am UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/2 "2004-10-03T08:21:15Z")

</div>

if you have MX (not '04) you should have a look in the samples folder where you installed it. there’s a timer example you might be able to find useful in there

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 3, 2004, 12:18pm UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/3 "2004-10-03T12:18:58Z")

</div>

> [@Skinny\_T](#):
>
> if you have MX (not '04) you should have a look in the samples folder where you installed it. there’s a timer example you might be able to find useful in there

ok i’ll give that a go thanks!

Anyone else have any more suggestions???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 3, 2004, 12:19pm UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/4 "2004-10-03T12:19:44Z")

</div>

Mad your an Aussie too!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 3, 2004, 2:22pm UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/5 "2004-10-03T14:22:10Z")

</div>

there’s also a sample in flashMX using that, in the samples dir.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 4, 2004, 5:02pm UTC](https://forum.kirupa.com/t/how-do-i-create-a-game-timer/66139/6 "2004-10-04T17:02:57Z")

</div>

I use setInterval for these kind of tasks. Let me look if I’ve got a script for this.

This is a snippet that I used for a game of mine a couple of months ago. You will have to modify it I think. Feel free to use it if its useful.

```php

function startTimer() {
	timerInterval = setInterval(goTimer, 1);
}
function goTimer() {
	startTime += 10;
	
	minutes = Math.floor(startTime / 1000 / 60);
	seconds = Math.floor((startTime / 1000) % 60);
	milliseconds = Math.floor((startTime) % 999);
	
	// display it
	displayTimer();
	
	// if pause pressed
	if (pause == true) {
		oldTime = startTime;
		startTime = 0;
		clearInterval(timerInterval);
	}
}
// display timer
function displayTimer() {
	if (minutes < 10) minuteDisplay = "0" + minutes;
	else minuteDisplay = minutes;
	
	if (seconds < 10) secondsDisplay = "0" + seconds;
	else secondsDisplay = seconds;
	
	if (milliseconds < 10) millisecondsDisplay = "00" + milliseconds;
	else if (milliseconds < 100) millisecondsDisplay = "0" + milliseconds;
	else millisecondsDisplay = milliseconds;
	
	// OUTPUT
	screen_play.block_time.lable = minuteDisplay + ":" + secondsDisplay + ":" + millisecondsDisplay;
}
// pause timer
//function pauseTimer() {
//	pause = true; // pause
	
	// blink timer
	
//}
// continue timer
function continueTimer() {
	pause = false; // no pause anymore
	startTime += oldTime; // old time plus new time
	
	startTimer(); // start timer again
}
// stop timer
function stopTimer() {
	clearInterval(timerInterval);
	totalTime = startTime;
}

```
