Whats the best way to wait for a few seconds ?

Blitz3D Forums/Blitz3D Beginners Area/Whats the best way to wait for a few seconds ?

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Blitz includes a Delay command, which effectively does the above. A Delay 3000 would be a 3 second delay.

Another approach is to set the count value to the Millisecs() count plus the time you want the delay to run like so:
waittime=Millisecs()+3000    ;set the wait time
while waittime>=Millisecs()
    ;do something during this time if you want
wend


The advantage of the count approach is that some condition could occur during the While statement that you might want to deal with without waiting, or you may have some useful stuff you could be doing during that time to help speed the game along. The advantage of very short delays might be to compensate for the speed of different PCs. However, to make this truely effective, you would begin with getting the waittime=Millisecs()+n early on, do a lot of stuff in between, the perform the wait loop at the end, before starting all over again like so:

Repeat

  waittime=Millisecs()+300

;perform all the actions related to one occurance in your
;program at this point in the program

;test for an end of program condition, whatever that might be

  While waittime>=Millisecs()

;check for any reason to continue before the timer ends here
    
  Wend
Forever  ;returns to the point where a new delay cycle starts

End