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 ?

Insane Games(Posted 2003) [#1]
Im working on a simple FPS game, and the player shold wait a few seconds on the reload time, but the game should continue (off course).

Whats the best way to do that ? (keep in mind it should be the same delay time on every machine..)


Gabriel(Posted 2003) [#2]
Well.. time is time on any machine, so go with Millisecs() over any frame-based delay.

I usually do something like this :

If MilliSecs()<=ReloadPause
     Update Moving Things
Else
     Check User Input

     If ReloadPressed Then ReloadPause=Millisecs()+3000
End if




Oldefoxx(Posted 2003) [#3]
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



Insane Games(Posted 2003) [#4]
Thanx, ill try it out.


sswift(Posted 2003) [#5]
"Whats the best way to wait for a few seconds?"

I find that tapping my foot works well. Sometimes I try crossing one arm over the other across my chest. Or occasionally I'll stand with one hand in my pocket so I don't look like some freak standing there with both arms just dangling at my sides. If I'm sitting at the time I might try the always popular resting of one hand on my thigh while I rest my chin on my other with my elbow on the arm of the chair or table.


Insane Games(Posted 2003) [#6]
If you don't wanna help, thats ok, but plz dont post. Thanks (for nothing).


Oldefoxx(Posted 2003) [#7]
Sounds like you are well versed and practiced in the area of waiting. Or possibly you just have a special gift.


sswift(Posted 2003) [#8]
Insane:
Your question was answered. I was merely trying to be funny. I thought it was rather clever anyhow. :-)


The best way to have somehting like a reload time is to use a system like my event system which I released for free a while back. I beleive it's in the code archives. Then you can use one set of code for all kinds of events and not just waiting for a reload to finish.


But for a quick solution do this:


Const RELOAD_TIME = 2000


In main loop:

If Reload = True
If Current_Time > Reload_End_Time
Reload = False
Reload_Gun()
EndIf
EndIf


And when the player needs to reload go:


Reload = True
Reload_End_Time = Current_Time + RELOAD_TIME


Insane Games(Posted 2003) [#9]
sorry, i was kind angry in the last post (for others reasons).

It's working fine here. In fact i have a simple multi-player stuff working already :)
Now im trying to implement those Cubic Splines stuff (im using BP pro), and a friend is working on some GUI stuff. ;)