How do I play a random sound from different sound clips?

Get help using Construct 2

Post » Thu Dec 15, 2016 2:47 pm

Hello all,

I'd like to play sounds randomly from a large list of sound clips.
I don't think it's possible to store audio objects in an array.
And I'd like to avoid a solution where I need to test a parameter (random number) against all audio objects represented by a number.
i.e.
If randomNb = 1 play("sound 1")
If randomNb = 2 play("sound 2")
etc.
I'm looking for something smart so that I could use for different situations (i.e. random jump sound, random walk sound, random background music, etc.)

Any ideas?

Ouais
B
6
S
1
Posts: 44
Reputation: 773

Post » Thu Dec 15, 2016 3:34 pm

You can store the names in an array.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Fri Dec 16, 2016 11:58 am

Thanks, I'll try.

Ouais
B
6
S
1
Posts: 44
Reputation: 773

Post » Fri Dec 16, 2016 1:49 pm

ouais25 wrote:Thanks, I'll try.

Ouais


You can play the sounds by their names.

If you name your sounds like
- jump_1
- jump_2


Audio - Play sound by name "jump_" & round(random(1,2)) //depending on your amount of sounds
Image Image iTunes: Match3 | Google Play: Match3
B
94
S
33
G
30
Posts: 1,099
Reputation: 27,645


Return to How do I....?

Who is online

Users browsing this forum: davidbox, Mayfly, Yahoo [Bot], zulerf and 6 guests