News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Using Timer() to create delays in your program.

Started by kevin, January 26, 2007, 05:59:58 PM

Previous topic - Next topic

kevin

  This little example shows how you can use the TIMER() function to suspend parts of your program, without halting the actual program execution.


PlayBASIC Code: [Select]
Do

Cls 0

; Display the
print Counter
print EndOfDelay

If Timer()>EndOfDelay

if SpaceKey()=true
; pause the counter for 1 second
EndOfDelay=timer()+1000
endif

Inc Counter

endif



; Selectively Display the Press Space Message
if State
centertext getscreenwidth()/2,getscreenheight()/2,"Press Space To Pause Counter"
endif

; Check if our Display Message has expired ?
if Timer()> DislayMessageUntil
; if so, flip the STATE flag
State=1-state
; and set the delay forward another 1/2 a second (1000 milliseconds = 1 second)
DislayMessageUntil=timer()+500
endif


Sync
loop