# Countdown from 20sec to 0sec

**URL:** <https://forum.kirupa.com/t/countdown-from-20sec-to-0sec/184056>\
**Category:** Uncategorized\
**Created:** [April 1, 2006, 12:27pm UTC](https://forum.kirupa.com/t/countdown-from-20sec-to-0sec/184056 "2006-04-01T12:27:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luksy](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@luksy](https://forum.kirupa.com/u/luksy)\
**Post date:** [April 1, 2006, 12:27pm UTC](https://forum.kirupa.com/t/countdown-from-20sec-to-0sec/184056/1 "2006-04-01T12:27:04Z")

</div>

Ok, i’ve searched but nothing. I have also seen the countdown tutorial but it’s no use for me because it countdowns to a chosen date.

So, what I need is a simple script that would use the dynamic text field with the variable of display to show the countdown from 20:00 seconds to 00:00 seconds (and then go to nextFrame();). Not from 20 to 0 but from 20:00, to 00:00. Which means milliseconds too.

I know it’s simple but I can’t do it ☹

Thanks a bunch!

---

<div class="post-metadata">

**Author:** ![therafiman](https://avatars.discourse-cdn.com/v4/letter/t/2acd7d/32.png) [@therafiman](https://forum.kirupa.com/u/therafiman)\
**Post date:** [April 1, 2006, 10:31pm UTC](https://forum.kirupa.com/t/countdown-from-20sec-to-0sec/184056/2 "2006-04-01T22:31:14Z")

</div>

Milliseconds go from 0 to 999 so you’ll have to update once every 10ms instead of once a ms. Therefore the milliseconds variable you’ll see below doesn’t really represent ms, its from 0 to 99 and represents 1/100’s of a second. Here’s the code:

// Initial values  
seconds = 20;  
milliseconds = 0;

// Call the updateTimer function once every 10 milliseconds  
myInterval = setInterval(updateTimer, 10);

function updateTimer()  
{[INDENT]// Update the timer  
[/INDENT][INDENT]if(milliseconds == 0)  
{[INDENT]if(seconds == 0)  
{[INDENT]// Countdown complete, Stop calling this function  
[/INDENT][INDENT]clearInterval(myInterval);

// Put whatever you want  
// it to do once finished here  
[/INDENT]}  
else  
{[INDENT]// Drop one second and reset the milliseconds

milliseconds = 99;  
seconds–;  
[/INDENT]}  
[/INDENT]}  
else milliseconds–;

// Format the numbers correctly if they  
// are the wrong length  
[/INDENT][INDENT]msString = milliseconds.toString();  
secString = seconds.toString();  
if(msString.length \< 2) msString = ‘0’ + msString;  
if(secString.length \< 2) secString = ‘0’ + secString;

// Update the text field

myText.text = secString + ‘:’ + msString;  
[/INDENT]}

---

<div class="post-metadata">

**Author:** ![luksy](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@luksy](https://forum.kirupa.com/u/luksy)\
**Post date:** [April 2, 2006, 7:10am UTC](https://forum.kirupa.com/t/countdown-from-20sec-to-0sec/184056/3 "2006-04-02T07:10:23Z")

</div>

thanks a lot!
