Objects that play random sounds

I want to make a piano that plays a random note everytime you interact with it, like in Animal Crossing with any of the instruments. I initially thought that you'd use a variable that chooses a random number, then have that number be the filename of the sound to be played, but apparently that's incorrect.

Here's what I've managed to do so far:

2465fmd.jpg


hte2r5.jpg


And before anyone asks, yes I did search on google. Many times in fact. No, they didn't help, otherwise I wouldn't have bothered to make a topic about it.

So my question is, how do I do it?
Your script call is defining a method that's already defined. You're not actually calling it.


You're also setting a variable to be a random number, but you're not using it. What's n? Where does it come from?


THIS is the script call you want to use after your Control Variables command.

Code:
Script: Sound.play_system_sound($game_variables[1])
I have 13 sound files, each with a different piano sound. I thought that maybe RPG Maker's play_system_sound script would work because it had [n], and I thought [n] depended on a number that a variable owned.

So that was my fault. I don't know RPG Maker's actions that scripts can command, such as play_system_sound.

What would I use to play custom sound effects?

EDIT: I figured it out using conditional branches, though if I could still get a script, it would help make the event's coding look neater.
Ah, yeah - you're assuming you can grab bits and pieces of existing scripts and they will just do what you want, when they're designed to do very specific things. play_system_sound means to play a sound that you've set up on the System tab.


You can name all your files in a similar way - Piano_1, Piano_2, Piano_3 ... Piano_13


Then you can use a script call to play a random one. I don't have Ace with me now, so I'm just guessing at this - if it doesn't work say so, and I'll find the correct command when I get home (or someone else will provide it for you). This method also removes the need for the variable for the random number:

Code:
Script: Audio.play_me(sprintf("Piano_%d", rand(13)+1))

Original thread: https://forums.rpgmakerweb.com/threads/objects-that-play-random-sounds.43013/