Randomized SFX interactions

Anyone who can help me with finding out how to randomize sound effects when interacting with an object? I want to make a piano interactable in my game, but I'm unsure on how to randomize the sounds.

If anyone could help that would be great, thank you in advance!
You could use control variables to set a variable to a random value, then have a conditional branch for each possible value which plays a different sound.
Are those SE (Sound Effects) specially made for this event? Number them, would be the easiest.

If your assets are named like Tone1.ogg, Tone2.ogg etc, you can do this:
Spoiler: How I did it at first.
1698226129130.png

Code:
AudioManager.playSe({ name: "Tone" + $gameVariables.value(123), volume: 90, pitch: 100, pan: 0 });

It now plays randomly tone1, tone2 or tone3,

Replace 123 with the ID of the variables you want to use.

EDIT: I can do even better:
Code:
var ID = Math.ceil(Math.random() * 3);
AudioManager.playSe({ name: "Tone" + ID, volume: 90, pitch: 100, pan: 0 });

With this code, you don't need a variable. It plays Tone1, Tone2 and Tone3 randomly.
Replace 3 with the highest possible ID of your tones.
You could use control variables to set a variable to a random value, then have a conditional branch for each possible value which plays a different sound.
Are those SE (Sound Effects) specially made for this event? Number them, would be the easiest.

If your assets are named like Tone1.ogg, Tone2.ogg etc, you can do this:
Spoiler: How I did it at first.
View attachment 281373
Code:
AudioManager.playSe({ name: "Tone" + $gameVariables.value(123), volume: 90, pitch: 100, pan: 0 });

It now plays randomly tone1, tone2 or tone3,

Replace 123 with the ID of the variables you want to use.

EDIT: I can do even better:
Code:
var ID = Math.ceil(Math.random() * 3);
AudioManager.playSe({ name: "Tone" + ID, volume: 90, pitch: 100, pan: 0 });

With this code, you don't need a variable. It plays Tone1, Tone2 and Tone3 randomly.
Replace 3 with the highest possible ID of your tones.

Thank you both for your replies! I'll try both methods to see which works best
Were you able to make it work now?
Were you able to make it work now?
I ran into a problem, Is this correct?
1698388275632.png
Like mentioned above, that only works if your sound effects are named like: 'Key1', 'Key2',' Key3' etc. That script is generating a number and adding it to the word 'Key' and then trying to play that SE.
I ran into a problem, Is this correct?
View attachment 281641
Like @rpgLord69 mentioned, you need to name the assets "Key1" "Key2" etc.

And the assets need to be in the /audio/se/ folder.
Like mentioned above, that only works if your sound effects are named like: 'Key1', 'Key2',' Key3' etc. That script is generating a number and adding it to the word 'Key' and then trying to play that SE.
Like @rpgLord69 mentioned, you need to name the assets "Key1" "Key2" etc.

And the assets need to be in the /audio/se/ folder.
Thank you so much! It works now, I appreciate your help so much! 👋
No problem.

I can randimize the pitch for you too, if you like. Then it sounds even more random. 1 file can already sound way different if you just change the pitch.

So if it is to have locks sound different each time, you can use different pitches instead, and just use the same sound over and over, of have multiple files  AND multiple pitches, then you'll end up with a huge number of different sounds.
No problem.

I can randimize the pitch for you too, if you like. Then it sounds even more random. 1 file can already sound way different if you just change the pitch.

So if it is to have locks sound different each time, you can use different pitches instead, and just use the same sound over and over, of have multiple files  AND multiple pitches, then you'll end up with a huge number of different sounds.
Sure! That would be really cool of you honestly
Ill do that later today. At the moment Im streaming.
Code:
var Pitch = Math.random() * 40 + 80;
var ID = Math.ceil(Math.random() * 3);
AudioManager.playSe({ name: "Tone" + ID, volume: 90, pitch: Pitch, pan: 0 });

Sorry for the late reply. Had a busy weekend.

However, here is the code which should make the pitch move up and down. (higher and lower toned)

Still, the 3 can be replaced with the maximum number of files.
Code:
var Pitch = Math.random() * 40 + 80;
var ID = Math.ceil(Math.random() * 3);
AudioManager.playSe({ name: "Tone" + ID, volume: 90, pitch: Pitch, pan: 0 });

Sorry for the late reply. Had a busy weekend.

However, here is the code which should make the pitch move up and down. (higher and lower toned)

Still, the 3 can be replaced with the maximum number of files.
1698960083595.png

Unsure if I'm doing this right
If you have 8 different key sounds, named key1, key2 etc, then it seems right to me.
Why? Did it not work?

Oh, I see what might go wrong... Try it like this:
Code:
var Pitch = Math.ceil(Math.random() * 40 + 80);
var ID = Math.ceil(Math.random() * 8);
AudioManager.playSe({ name: "Key" + ID, volume: 90, pitch: Pitch, pan: 0 });

Original thread: https://forums.rpgmakerweb.com/threads/randomized-sfx-interactions.162378/