Play Random sound when something happens

For questions about using Classic.

Post » Thu Oct 18, 2012 4:09 pm

In my game, when bullet hits the target there is usually a "hit1.mp3" playing.

Now, I have 3 sounds stored in my folder "hit1.mp3, hit2.mp3, hit3.mp3"
How to play this 3 sounds randomly when bullet hits the target?
B
2
Posts: 3
Reputation: 356

Post » Fri Oct 19, 2012 4:22 pm

Just make the file path this way:
AppPath & "hit" & 1+random(3) & ".mp3"

If it doesn't work for, change the number to a string this way:
AppPath & "hit" & str(1+random(3)) & ".mp3"

Random() is zero indexed, so random(3) returns 0, 1 or 2. That's why it's 1+random(3), since your hit sounds don't start from 0.
B
11
S
2
G
3
Posts: 100
Reputation: 2,150

Post » Fri Oct 19, 2012 5:15 pm

Works great! Thank you :)
B
2
Posts: 3
Reputation: 356


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests