How to make an event play random sound clip?
Dell7730
Member, PRO Posts: 388
I would like an event to play a different audio every time from a few selection
Best Answer
-
KevinCross London, UKPosts: 1,894
I don't think you can play a random sound on a single line like you can show a random image so try it with a Change Attribute and a Rule i.e.
Change Attribute: game.randomSoundNumber = random(1, 5)
Rule: If game.randomSoundNumber = 1
Play sound 1
Rule: If game.randomSoundNumber = 2
Play sound 2
Rule: If game.randomSoundNumber = 3
Play sound 3
etc.Where I've got Play sound 1 and Play sound 2 is where you'd put the play sound behavour and then pick the sound file you want to play.
Answers
Expression access to the play sound behaviour would really open up a world of possibilities. It would be great to name sound effects FX1, FX2, FX3 . . (and so on) and then being able to do things like play sound "FX"..(random (1,8))
IT WORKS!!!!! > @KevinCross said:
IT WORKS! THANKS
Follow up, is there a way to make sure it won't repeat a clip until all the other choices have been used? The code works, just that sometimes it repeats some of the choices.
@Dell Agarpo Why do you not use a variable, e.g. SoundCounter ("FX"..game.SoundCounter) and a count it up everytime. If SoundCounter reach Maximum just set it back to 1.
Okay it is a list of sounds and not random, but it won't repeat the same sound multiple times. You could also random the first sound, e.g. you have 10 sounds, then don't set it back to 1 if it reach the maximum, just random(1,9). In the worst case you have multiple times sound9, sound10, sound9, sound10,...
http://forums.gamesalad.com/discussion/68841/random-numbers-no-repeating