|
precise countdown timer
#281698
07/28/09 07:44
07/28/09 07:44
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
Hi, I'm making some coundown timer (minutes:seconds) and i want this to be precise for a second... Here's the code setup:
var milliseconds = 0;
var seconds = 10;
var minutes = 01;
....
PANEL* pan_time =
{
pos_x = 740;
pos_y = 5;
digits(200, 70, "min: %0.f", system_font, 1, minutes);
digits(100, 90, "sec: %0.0f", system_font, 1, seconds);
digits(100, 110, "msecs: %0.f", system_font, 1, milliseconds);
flags = SHOW;
}
....
function myTimer_startup()
{
while (minutes >= 0)
{
milliseconds += (timer() / 1000);
if (milliseconds > 1000 && seconds > 0)
{
milliseconds -= 1000;
seconds -= 1;
}
if(seconds == 0 && minutes > 0)
{
minutes -= 1;
seconds = 10;
}
wait (1);
}
milliseconds = 0;
}
but i've found out that "milliseconds" value is still computing & wouldn't stop even it's already break out in the loop & reset its value to 0.. this would cause a crash if this variable "milliseconds" would excess on its data value it could contain. So, i'm wondering if this timer() would always run in the backround... it's so strange. Hope someone could help. Thanks
|
|
|
Re: precise countdown timer
[Re: boyax]
#281706
07/28/09 08:46
07/28/09 08:46
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
Member
|
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Hi boyax,
I think this is an infinite loop (due to your condition minutes >= 0, wherein minutes is always equal to 0 as its minimum value)that's why your milliseconds is still incrementing..
Can't is not an option™
|
|
|
Re: precise countdown timer
[Re: seecah]
#281707
07/28/09 08:47
07/28/09 08:47
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
Member
|
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Maybe you can add your code another condition to break it.. if (seconds == 0 && 0 == minutes){ break;}
#include <acknex.h>
#include <default.c>
var milliseconds = 0;
var seconds = 10;
var minutes = 01;
PANEL* pan_time =
{
pos_x = 740;
pos_y = 5;
digits(200, 70, "min: %0.f", *, 1, minutes);
digits(100, 90, "sec: %0.0f", *, 1, seconds);
digits(100, 110, "msecs: %0.f", *, 1, milliseconds);
flags = SHOW;
}
function myTimer_startup()
{
while (minutes >= 0)
{
milliseconds += (timer() / 1000);
if (milliseconds > 1000 && seconds > 0)
{
milliseconds -= 1000;
seconds -= 1;
}
if(seconds == 0 && minutes > 0)
{
minutes -= 1;
seconds = 10;
}
[b]if (seconds == 0 && 0 == minutes){ break;}[/b]
wait (1);
}
milliseconds = 0;
}
void main()
{
video_set(1024,768,32,2);
myTimer_startup();
}
Tested... :-)
Can't is not an option™
|
|
|
Re: precise countdown timer
[Re: boyax]
#281711
07/28/09 08:59
07/28/09 08:59
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
Member
|
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Yeah right... maybe your just distant apart... "taga asa ka bai? asa ka ga-work?"
Can't is not an option™
|
|
|
Re: precise countdown timer
[Re: boyax]
#281713
07/28/09 09:07
07/28/09 09:07
|
Joined: Apr 2009
Posts: 248 Philippines
seecah
Member
|
Member
Joined: Apr 2009
Posts: 248
Philippines
|
Maayo nagkita ta diri sa forum... kita ray pinoy diri... wala siguro na sila kasabot sa atong giistoryahan.. naruto na imong avatar? ka cute pud sa imong name oi... "boyax"... mura mag mamirahay sa Lorega...hahahahahahah
Can't is not an option™
|
|
|
Re: precise countdown timer
[Re: uone]
#281719
07/28/09 09:24
07/28/09 09:24
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
hahaha... maau nagkita ta diri sa forum bai! unsa kaha buhat ta ug chapter diri sa pinas?hehe.. @uone: kuyaw sa imong mata... hehehe... btw, basin ma-banned ta dah..
|
|
|
|