UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on February 10, 2023, 05:15:46 AM

Title: Wait Seconds without using Timer
Post by: kevin on February 10, 2023, 05:15:46 AM

    Wait Seconds without using Timer

   This function will wait an approximate number of seconds for the user.   It does this by polling the CurrentTime$() function in a loop until it changes.   Each time i changes we know that one second has passed.  So if we call repeat this process X number of times our program will wait X number of seconds.   


[pbcode]

   print CurrentTime$()
   Sync
   WaitSeconds(10)
   
   print CurrentTime$()

   Sync
   waitkey
   


Function WaitSeconds(NumberOfSeconds)
   
   for lp=1 to NumberOfSeconds
         local t$=currenttime$()
         repeat
            wait 10
         until  t$ <>currenttime$()
         wait 500
   next   
EndFunction


[/pbcode]


      PLayBASIC Documentation

      - CurrentTime$() (http://playbasic.com/help.php?page=TIME_AND_DATE.CURRENTTIME$)
      - Timer() (http://playbasic.com/help.php?page=TIME_AND_DATE.TIMER)
      - Wait (http://playbasic.com/help.php?page=TIME_AND_DATE.WAIT)