how do i get different sounds to play each time audio.loadsound is called?

Hi everyone I have quick and hopefully easy question…So, I am making a game where each time 3 objects are matched a sound is played.  I have it working with one sound. However, I would like to have a different sound played each time the 3 objects are matched so its not so repetitive.  I have a totally of 5 sounds i want to use

sound1,sound2,sound3,sound4,sound5 all are .wav.

thank you

this is what i have:

local makePopSound = false

if makePopSound then

    makePopSound = false

    playSound(“sound1”)

   end

then in my main.lua i have :

local sounds = {}

sounds[“select”] = audio.loadSound(“sounds/select.mp3”)

sounds[“sound1”] = audio.loadSound(“sounds/sound1.wav”)

Hello! So i think i understand what you want here… 

pop = {} pop[1] = audio.loadSound("sound1.wav") pop[2] = audio.loadSound("sound2.wav") pop[3] = audio.loadSound("sound3.wav") local function playPop() local thisPop = math.random(#pop) audio.play(pop[thisPop]) end Runtime:addEventListener( "collision", playPop )

Good Luck!

Hi SonicX278

Fantastic reply! 

Should we put all of that line of code into the ‘main.lua’ file then? 

Thanks

Thank you!

Well you out the the code where the sound is going to be played… Like game.lua if your using composer but if you are using main.lua for your whole game then ya it’ll go in main…

Hello! So i think i understand what you want here… 

pop = {} pop[1] = audio.loadSound("sound1.wav") pop[2] = audio.loadSound("sound2.wav") pop[3] = audio.loadSound("sound3.wav") local function playPop() local thisPop = math.random(#pop) audio.play(pop[thisPop]) end Runtime:addEventListener( "collision", playPop )

Good Luck!

Hi SonicX278

Fantastic reply! 

Should we put all of that line of code into the ‘main.lua’ file then? 

Thanks

Thank you!

Well you out the the code where the sound is going to be played… Like game.lua if your using composer but if you are using main.lua for your whole game then ya it’ll go in main…