GLBasic forum

Main forum => GLBasic - en => Topic started by: MrPlow on 2013-Aug-03

Title: Timer countdown
Post by: MrPlow on 2013-Aug-03
Hi,

How should I go about doing countdown timer?
I can get a count up timer working using GETTIMERALL() but am scratching my head for a workable countdown with
hh:mm:ss format

Thks
Gary
Title: Re: Timer countdown
Post by: MrPlow on 2013-Aug-03
Also is there a Bug in GetTimer() for GLB v11?

I notice that SHOWSCREEN is not resetting the time - seems to take the time from the very first SHOWSCREEN not the most recent. My clock is losing 2-3 secs at the start due to a SLEEP of 3 secs before starting my count.

Gary
Title: Re: Timer countdown
Post by: bigsofty on 2013-Aug-03
Off the top of my head...

a=gettimerall()+((h*60*60)+(m*60)+s)*1000
while 1
  if gettimerall()>a then foo()
wend
Title: Re: Timer countdown
Post by: MrTAToad on 2013-Aug-04
GETTIMERALL() wont reset each SHOWSCREEN.  GETTIMER() should
Title: Re: Timer countdown
Post by: MrPlow on 2013-Aug-04
I have a counter working but say I want to pause it - how should I track the elasped time to make the counter continue from when paused?

01h 20m 30secs (its paused here)

However gettimerall is still counting away (which above is based on) but I want it to stay at 01h 20m 30secs

I have tried to use another value which is set to gettimerall on pausing but it doesnt work for me - my logic is wrong somewhere...

I have something like this for pausing where adder1 and adder2 are supposed to take a snap of the time difference
(i am nearly there but something is throwing out my timings)

IF KEY(57)

   SLEEP 100
   newset = ply1
   
   IF ply1 = 1 THEN adder1 =  adder1 + (GETTIMERALL()  - lastpress ) - 100
   IF ply1 = 2 THEN adder2 =  adder2 + (GETTIMERALL()  - lastpress ) - 100
   
   IF newset = 2 THEN ply1 = 1
   IF newset = 1 THEN ply1 = 2
   
   
   // get time at last press of button
   lastpress = GETTIMERALL()
   
ENDIF

Title: Re: Timer countdown
Post by: MrPlow on 2013-Aug-05
I've sorted this using a simpler method. :booze: