delay question

BlitzMax Forums/BlitzMax Programming/delay question

Cruis.In(Posted 2005) [#1]
hey everyone, I just need a fake delay. Here's the problem, using Delay, delay's all program execution as you know, so for a game it really isn't feasible.

If KeyHit(KEY_TAB)
PlaySound(Sound)
Delay(5000 * delta)

statement1
statement2
statement3
end if

so basically the sound is 5 seconds long that plays there, what I want is statements 1-3 to be carried out AFTER the sound finishes playing, this code does it, but PAUSES everything, is there a way to delay those 3 statements from running until the 5 seconds, withut "delay".
thanks
?


klepto2(Posted 2005) [#2]

If Keyhit(Key_Tab)
 Channel = playSound(Sound)
Endif

If ChannelPlaying(Channel) = False
state1
state2
state3
Endif


I hope this helps you ( not tested, but should work)


Cruis.In(Posted 2005) [#3]
If KeyDown(KEY_TAB)
Local channel = PlaySound(sound)


If ChannelPlaying(channel) = False
statement1
statement2
statement3
End If
End If

no go. the statements don't execute.


REDi(Posted 2005) [#4]
To answer your "fake delay" question...
Local DelayStopTime=Millisecs()+5000

' >>> In your main loop
If DelayStopTime And Millisecs()=>DelayStopTime Then DelayStopTime=0 ; *DO WHATEVER*


But I think klepto2 suggestion is more what you need.

BTW why are you multiplying your delay time by delta? :)


Cruis.In(Posted 2005) [#5]
dunno.. 5000 millisecs = 5 seconds already doesnt it :)
i must not be using klepto own properly that why i posted how i implemented it. the statements dont execute.

i used yours, and they execute immediately, even the first time, without a 2 second wait


Hotcakes(Posted 2005) [#6]
Cruis.In, klepto's routine works, but you need to put it in a loop. If you don't, it will start the sound and then run onto the next instruction a microsecond or less later, and check to see if the sound is still playing. Obviously it will be... you need to continuously check for long enough for the sound to stop playing. Maybe something like:

Repeat
  If Keyhit(Key_Tab)
   Channel = playSound(Sound)
  Endif

  If ChannelPlaying(Channel) = False Then Exit
Forever

state1
state2
state3



Yan(Posted 2005) [#7]
Klepto2's example should have worked. Are you sure you implemented it correctly?

Here's a more complete example...



Cruis.In(Posted 2005) [#8]
i have it correct, it doesnt work, the block of statements doesnt execute.


Yan(Posted 2005) [#9]
...


Cruis.In(Posted 2005) [#10]
thanks anyway :)


tonyg(Posted 2005) [#11]
Did you *really* use this...
If KeyDown(KEY_TAB) 
Local channel = PlaySound(sound)
If ChannelPlaying(channel) = False
statement1
statement2
statement3
End If 
End If 

?
If so, you have your endif statements in the wrong place.
Try this...
Graphics 640,480,0
sound=LoadSound("shoot.wav")
While Not KeyHit(key_escape)
    If KeyDown(KEY_TAB) Local channel = PlaySound(sound)
    If channel<> Null
 	  If ChannelPlaying(channel) = False
	    DrawText "This is displayed when sound has finished playing",0,0
	    DrawText "... so is this",0,10
	  End If 
	EndIf
	Flip
Wend