Play Random Sound for the Same Object

Get help using Construct 3!

Post » Wed Jul 05, 2017 3:25 am

In Construct 2 is there a way to make it so the same object plays multiple sound files when the same action happens? So when I hit or attack something it plays multiple sound files?
B
6
S
1
Posts: 3
Reputation: 358

Post » Wed Jul 05, 2017 8:19 am

Do you mean that on the same event e.g. Object A collides with Object B, a random sound will be played?

If so, one way to do this is to give your sounds a set of indexed filenames like sfx_0, sfx_1, sfx_2.

Then on your trigger event use the audio action "play (by name)"; in the audio file name field write: "sfx_"&choose(0,1,2)

You could of course use choose with non-indexed file names e.g. choose("bang","laser","grenade"), but indexing gives you more flexibility, especially if you have a lot of sounds to pick between - you may even want to switch from using choose() to floor(random(min,max)) as this would allow you even more control over what was played.

For bonus variation add the "Set playback rate" action directly underneath this action, setting the playback rate to a random number.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Sat Jul 08, 2017 4:18 am

thats actually pretty smart. id've told you to set a variable for sound played, but then youd have to say 1 = sound1 2 = sound2 3=sound3, where as indexed names you can say "sound"&Random(x,y) and it solves for the whole lot.
B
23
S
12
G
1
Posts: 109
Reputation: 2,801

Post » Mon Oct 02, 2017 3:48 pm

mekonbekon You my friend are a genius I was at a complete stop in my development and couldn't continue on. My main problem is I can't move on till I fix the issue at hand and you have done just that for me you are awesome and I thank you for your post. Keep up the great work.
B
15
S
5
G
1
Posts: 1
Reputation: 1,727

Post » Mon Oct 02, 2017 5:06 pm

@x9xReBeLx2x

You're welcome, glad to be able to help out :)
B
20
S
9
G
4
Posts: 473
Reputation: 4,260


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 2 guests