UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on January 26, 2007, 05:59:58 PM

Title: Using Timer() to create delays in your program.
Post by: kevin on January 26, 2007, 05:59:58 PM
  This little example shows how you can use the TIMER() function to suspend parts of your program, without halting the actual program execution.


[pbcode]

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


[/pbcode]