Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Akow, degenerate_762), 1,430 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
precise countdown timer #281698
07/28/09 07:44
07/28/09 07:44
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline 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:
Code:
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 Offline
Member
seecah  Offline
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 Offline
Member
seecah  Offline
Member

Joined: Apr 2009
Posts: 248
Philippines
Maybe you can add your code another condition to break it..

if (seconds == 0 && 0 == minutes){ break;}

Code:
#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: seecah] #281708
07/28/09 08:53
07/28/09 08:53
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
got it! so dumb... Thanks! grin

[off-topic] you're in the philippines too??? looks cool. cool

Last edited by boyax; 07/28/09 08:58.
Re: precise countdown timer [Re: boyax] #281711
07/28/09 08:59
07/28/09 08:59
Joined: Apr 2009
Posts: 248
Philippines
seecah Offline
Member
seecah  Offline
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: seecah] #281712
07/28/09 09:03
07/28/09 09:03
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
hahahaaha... naa rako diri sa cebu... ikaw? ka-cute sa imo iring oi... hehehe...
mo-dula ka ug dota? dota ta! wink

Re: precise countdown timer [Re: boyax] #281713
07/28/09 09:07
07/28/09 09:07
Joined: Apr 2009
Posts: 248
Philippines
seecah Offline
Member
seecah  Offline
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: seecah] #281714
07/28/09 09:09
07/28/09 09:09
Joined: Jun 2009
Posts: 17
Cebu Philippines
U
uone Offline
Newbie
uone  Offline
Newbie
U

Joined: Jun 2009
Posts: 17
Cebu Philippines
hi guys,

taga asa mo sa cebu? kuyawa diay anang boyaks oi..

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 Offline OP
Member
boyax  Offline 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..


wink


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1