Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Blitz => Topic started by: Hotshot on March 16, 2007

Title: 20 sec timer?[BB2D]
Post by: Hotshot on March 16, 2007
Code: [Select]
Graphics 640,480,16,2
SetBuffer BackBuffer()

Time=MilliSecs()
Repeat
Text 0,0,time
Until MilliSecs() < Time + 20000 ; 20 seconds

I got the demo up and running but I want to know how do in 20 seconds timer?

I am getting abit mixed up!

cheers

Title: Re: 20 sec timer?
Post by: Shockwave on March 16, 2007
Should work, dunno I don't have Blitz on this computer :D

Code: [Select]
Graphics 640,480,16,2
SetBuffer BackBuffer()

Time=MilliSecs()
Repeat

Text 0,0,MilliSecs()-time
Flip
Cls
Until (MilliSecs() - Time) >= 20000 ; 20 seconds
Title: Re: 20 sec timer?
Post by: Paul on March 16, 2007
@Hotshot you just got the < the wrong way round ;)

Code: [Select]
Graphics 640,480,16,2
SetBuffer BackBuffer()

Time=MilliSecs()
Repeat
Text 0,0,time
Until MilliSecs() > Time + 20000 ; 20 seconds
Title: Re: 20 sec timer?
Post by: Hotshot on March 16, 2007
I nearly got it right but thank for helping and also I put
delay(1000) to slow the timer down.

that great

cheers
Title: Re: 20 sec timer?
Post by: Shockwave on March 16, 2007
When you put your delay of 1000 in you will slow your whole program down..


There is also a problem with the code you and paul posted, you won't be able to see the timer because you never cleared the screen...

Use this instead; (not tested but if I don't know how to write a blitz program by now I should be ashamed :P )

Code: [Select]
;----------------
; Open Screen;
;----------------

Graphics 640,480,16,2
SetBuffer BackBuffer()

Global Time=MilliSecs()

;----------------
; Main Loop Repeats until 20 seconds is over or escape pressed.
;----------------

Repeat

clock()
Flip
Cls

Until (MilliSecs() - Time) >= 20000 Or KeyDown(1)

;----------------
; Display How Many Seconds Have Passed.
;----------------


Function clock()
elapsed = (MilliSecs()-time) /1000
Text 0,0,elapsed
End Function
Title: Re: 20 sec timer?
Post by: mike_g on March 16, 2007
Damn shockwave beat me to it....

And yeah, if you are using delay(1000), then it will also delay the rest of your program so you will only get 1 frame per second.

By dividing the time by 1000, you can chop off the milliseconds :)


Title: Re: 20 sec timer?
Post by: Paul on March 16, 2007
works like a charm SW!
Title: Re: 20 sec timer?
Post by: Shockwave on March 16, 2007
Thanks :)

Lol, sorry Mike. I didn't realise you were replying to him.
Let's hope that Hotshot saw the code otherwise he will have an intro with an.. erm.. Choppy frame rate ;)