Wait until a sound has completed / play sounds one after another?
akimbo
Member Posts: 6
Hi,
I'd like to find a way to play a sound, and have other behaviors in that actor pause until the sound has completed. I expected that "Run to completion" would accomplish this, but it doesn't -- the following set plays all the sounds at once.
I got something to work using a timer at each step (after 1 second play sound 2, after 2 seconds play sound 3, etc.) but that seems inelegant. Is there a better way to do this than using lots of timers?
Thanks,
Doug
I'd like to find a way to play a sound, and have other behaviors in that actor pause until the sound has completed. I expected that "Run to completion" would accomplish this, but it doesn't -- the following set plays all the sounds at once.
I got something to work using a timer at each step (after 1 second play sound 2, after 2 seconds play sound 3, etc.) but that seems inelegant. Is there a better way to do this than using lots of timers?
Thanks,
Doug
Comments
The main problem is that GS doesn't have a quick "built in" way to use an .mp3 length as a timer. This means you'll have to program the behaviors to trigger when you want. As you stated, the method you described with timers for each sound isn't the most elegant solution, but it's close.
What may be the best solution is instead of putting each behavior inside of a timer, you can assign an integer attribute to handle timing the behaviors. So create this integer attribute on the attributes box (on the left side when inside the actor), which you can give a name like "soundTrigger." This integer attribute will control each behavior instead of individual timers. Here's what the code would look like.
_______________________________________________________
[Attribute] [soundTrigger] = 0
[Play Sound] or any behavior
TIMER
After "x" seconds [Change Attribute soundTrigger to soundTrigger+1]
_______________________________________________________
Then you wrap each behavior in the rule with the soundTrigger attribute instead of a timer for each. Less timers is better, and this way there's only one timer doing all the work. There's also a method for timing that is better than using a timer behavior but I can explain/show this method later.
If each sound or behavior is not at the same length (in your example you said 1 second apart) there is a way to easily space them apart at various lengths using a table. I can explain and create an example project later.
Feel free to email me or Skype. I sent a PM back with my info. Thanks!
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS