I'm making a top down shooter and it's going pretty well. However I have run into a problem: When bullets hit a wall, I want them to make a ricochet sound. I have 9 ricochet sounds that I want to use (ric1, ric2, ric3 etc.), and I want one of them to be randomly played when the bullet hits the wall. What is the easiest way of doing this?
i haven't tried this myself but try doing this: give the bullet a variable and name it "sfx" or whatever you want and you can default the value to whichever number out of the 9 you will be using
+ on collision between bullet and wall (or when bullet overlaps wall, try both) - set variable "sfx" to a random number between 0 and 8 (or 1 and 9, whatever) + (subevent) variable "sfx" is equal to 0 - play bulletSFX0.mp3 - destroy bullet + (subevent) variable "sfx" is equal to 1 - play bulletSFX1.mp3 - destroy bullet etc ...
taking into account the order of events, this works in my head; the main event should generate a value for the variable, "sfx" and with the condition for bullet collision/overlapping already met in the main event all the subevents have left to do is check the value stored in the variable
just make sure that the "destroy bullet" action is the last one made as you will require the value stored in the variable to choose which sound file to play
random(9) returns 0-8, so unless your sounds are ric0, ric1, ric2 etc, you want to add 1 to that. Also, the & operator is better for combining strings and numbers in to strings. Try using the filename: