Wait until a sound has completed / play sounds one after another?

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

image

Comments

  • CrazybreadmanCrazybreadman Member Posts: 674
    edited June 2013
    Hey Doug, you contacted me about "On Demand" help so here's a free sample. ;)

    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!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I overcame this issue for my play by play announcer feature in our game Puck It. You can use self.time and a start.time self attribute instead of a GS timer behavior. Also use a self integer called play.next and keep adding to the number which triggers the next sound based on the count total. This worked well for me. Sometimes there just aren't elegant ways to do specific things in Gamesalad especially when dealing with sound or music files.
Sign In or Register to comment.