{table with sounds files} i need help to playing random and when a sound start, it have to finish completely, then start the next random one...

[lua]sonido1 = audio.loadSound( “sonido1.mp3” )
sonido2 = audio.loadSound( “sonido2.mp3” )
sonido3 = audio.loadSound( “sonido3.mp3” )

sonidos = {sonido1, sonido2, sonido3}

for i=1, #sonidos do
math.randomseed(os.time())
aleatorio = math.random (#sonidos)
playSound ()
audio.play (sonidos[aleatorio], {onComplete = ¿?¿?¿?¿?¿? })
table.remove (sonidos, aleatorio)
end[/lua]

This way plays the 3 sounds at the same time, i need do something inside “for loop” cause i need the random order of the sound table.

HELP ME PLEASE!

I found a solution for you

https://www.youtube.com/watch?v=1hf0HYq5yzc

at 10:20 he starts talking about the math random… thats whats you need… if you still need help ill be able to help in a day or two… in currently on vacation.

Tanks for you reply, but this doesn’t help me :frowning:

i havent problem with the random thing, I understand every thing about this.

I need help with the onComplete parameter inside audio.play command.

Cause in this moment I want that Corona sleeps, wait, or something, while is playing a sound, when its finished, i want the control to main threard and continue with the next for loop iteration.

 I NEED A PRO USER HELP!!!

You don’t need a pro user to help… You need to explain yourself problem more understandably

But is this what you need?

So there are 3 songs 1 - 2 - 3…
And when game starts song one starts playing… And when song 1 ends song 2 starts playing and then when song 2 ends song 3 starts playing then when song 3 ends then song 1 starts playing… And so on…

Is that what you want? If not you need to explain your problem better… Thanks!

This code will (should, assuming I made no typos) play the sounds one at a time in a random order then stop:

math.randomseed(os.time()) local sonido1 = audio.loadSound( "sonido1.mp3" ) local sonido2 = audio.loadSound( "sonido2.mp3" ) local sonido3 = audio.loadSound( "sonido3.mp3" ) local sonidos = {sonido1, sonido2, sonido3} local playRandom playRandom = function () if( #sonidos == 0 ) then return end local aleatorio= math.random(1,#sonidos) audio.play (sonidos[aleatorio], { onComplete = playRandom } ) table.remove ( sonidos, aleatorio ) end playRandom()

This will randomize the table initially and play over and over.  It re-shuffles on each time through the table.

math.randomseed(os.time()) local function shuffleTable( t ) local rand = math.random assert( t, "shuffleTable() expected a table, got nil" ) local iterations = #t local j for i = iterations, 2, -1 do j = rand(i) t[i], t[j] = t[j], t[i] end end local sonido1 = audio.loadSound( "sonido1.mp3" ) local sonido2 = audio.loadSound( "sonido2.mp3" ) local sonido3 = audio.loadSound( "sonido3.mp3" ) local sonidos = {sonido1, sonido2, sonido3} local aleatorio = #sonidos local playRandom playRandom = function () aleatorio = aleatorio + 1 if( aleatorio \> #sonidos ) then aleatorio = 1 shuffleTable( sonidos ) end audio.play (sonidos[aleatorio], { onComplete = playRandom } ) end playRandom()

Thx again for your replay.

I need what you exactly said. But I need the all sounds inside a table. why? Cause I want to play randomly. And why more? Cause tomorrow y want yo change the songs, or add songs, only i have to add sounds in the table and finish.

So I add the sounds:

sound1 = audio.loadSound( "sound1.mp3" ) sound2 = audio.loadSound( "sound2.mp3" ) sound3 = audio.loadSound( "sound3.mp3" ) sounds = {sound1, sound2, sound3}

Next, I need to do a for loop to roam the table randomly, and i doesn’t want to repeat a sound.

for i=1, #sounds do math.randomseed(os.time()) randomSound = math.random (#sound) playSound () audio.play (sounds[randomSound]) table.remove (sonidos, aleatorio) end

Now, i play 3 sounds randomly. But corona do so fat, and practically, 3 sounds is playng at the same time… i need something that i can do corona sleep, wait, or use better the optional parameter inside audio.play onComplete…

but its doesn’t work…

do you understand me now?

thanks you!!!

Very very thanks roaminggamer!!!

im gonna to tell you the full problem (maybe I should have done before). Cause I thought if I find another way to solution I can fix my problems… so there we go!

advertising1 = audio.loadSound( "advertising1.mp3" ) advertising2 = audio.loadSound( "advertising2.mp3" ) advertising3 = audio.loadSound( "advertising3.mp3" ) advertisingTable = {advertising1, advertising2, advertising3} math.randomseed(os.time()) local sound1 = audio.loadSound( "sound1.mp3" ) local sound2 = audio.loadSound( "sound2.mp3" ) local sound3 = audio.loadSound( "sound3.mp3" ) local sound4 = audio.loadSound( "sound4.mp3" ) local soundsTable = {sound1, sound2, sound3, sound4} initialElements = #soundsTable local playRandom playRandom = function () if( #soundsTable == 0 ) then return elseif (#soundsTable == initialElements/2) then local randomAdvertising= math.random(1,#advertisingTable) audio.play (advertisingTable[randomAdvertising]) end local randomSound= math.random(1,#soundsTable) audio.play (soundsTable[randomSound], { onComplete = playRandom } ) table.remove ( soundsTable, randomSound ) end playRandom()

I need what you know  about the sounds (now i put 4, you will know why…) cause i want that in the exactly middle of the iterations sounds, play a random advertising sound, and then continue in with the sounds left…

In the code i did, as you can see, this works perfect… but i have one problem… the random advertising sound, playing in the correct position, but doesn’t wait anyone… and i can hear the advertising sound a the same time that the position 3 sound… you understand me?

I found a solution for you

https://www.youtube.com/watch?v=1hf0HYq5yzc

at 10:20 he starts talking about the math random… thats whats you need… if you still need help ill be able to help in a day or two… in currently on vacation.

Tanks for you reply, but this doesn’t help me :frowning:

i havent problem with the random thing, I understand every thing about this.

I need help with the onComplete parameter inside audio.play command.

Cause in this moment I want that Corona sleeps, wait, or something, while is playing a sound, when its finished, i want the control to main threard and continue with the next for loop iteration.

 I NEED A PRO USER HELP!!!

You don’t need a pro user to help… You need to explain yourself problem more understandably

But is this what you need?

So there are 3 songs 1 - 2 - 3…
And when game starts song one starts playing… And when song 1 ends song 2 starts playing and then when song 2 ends song 3 starts playing then when song 3 ends then song 1 starts playing… And so on…

Is that what you want? If not you need to explain your problem better… Thanks!

This code will (should, assuming I made no typos) play the sounds one at a time in a random order then stop:

math.randomseed(os.time()) local sonido1 = audio.loadSound( "sonido1.mp3" ) local sonido2 = audio.loadSound( "sonido2.mp3" ) local sonido3 = audio.loadSound( "sonido3.mp3" ) local sonidos = {sonido1, sonido2, sonido3} local playRandom playRandom = function () if( #sonidos == 0 ) then return end local aleatorio= math.random(1,#sonidos) audio.play (sonidos[aleatorio], { onComplete = playRandom } ) table.remove ( sonidos, aleatorio ) end playRandom()

This will randomize the table initially and play over and over.  It re-shuffles on each time through the table.

math.randomseed(os.time()) local function shuffleTable( t ) local rand = math.random assert( t, "shuffleTable() expected a table, got nil" ) local iterations = #t local j for i = iterations, 2, -1 do j = rand(i) t[i], t[j] = t[j], t[i] end end local sonido1 = audio.loadSound( "sonido1.mp3" ) local sonido2 = audio.loadSound( "sonido2.mp3" ) local sonido3 = audio.loadSound( "sonido3.mp3" ) local sonidos = {sonido1, sonido2, sonido3} local aleatorio = #sonidos local playRandom playRandom = function () aleatorio = aleatorio + 1 if( aleatorio \> #sonidos ) then aleatorio = 1 shuffleTable( sonidos ) end audio.play (sonidos[aleatorio], { onComplete = playRandom } ) end playRandom()

Thx again for your replay.

I need what you exactly said. But I need the all sounds inside a table. why? Cause I want to play randomly. And why more? Cause tomorrow y want yo change the songs, or add songs, only i have to add sounds in the table and finish.

So I add the sounds:

sound1 = audio.loadSound( "sound1.mp3" ) sound2 = audio.loadSound( "sound2.mp3" ) sound3 = audio.loadSound( "sound3.mp3" ) sounds = {sound1, sound2, sound3}

Next, I need to do a for loop to roam the table randomly, and i doesn’t want to repeat a sound.

for i=1, #sounds do math.randomseed(os.time()) randomSound = math.random (#sound) playSound () audio.play (sounds[randomSound]) table.remove (sonidos, aleatorio) end

Now, i play 3 sounds randomly. But corona do so fat, and practically, 3 sounds is playng at the same time… i need something that i can do corona sleep, wait, or use better the optional parameter inside audio.play onComplete…

but its doesn’t work…

do you understand me now?

thanks you!!!

Very very thanks roaminggamer!!!

im gonna to tell you the full problem (maybe I should have done before). Cause I thought if I find another way to solution I can fix my problems… so there we go!

advertising1 = audio.loadSound( "advertising1.mp3" ) advertising2 = audio.loadSound( "advertising2.mp3" ) advertising3 = audio.loadSound( "advertising3.mp3" ) advertisingTable = {advertising1, advertising2, advertising3} math.randomseed(os.time()) local sound1 = audio.loadSound( "sound1.mp3" ) local sound2 = audio.loadSound( "sound2.mp3" ) local sound3 = audio.loadSound( "sound3.mp3" ) local sound4 = audio.loadSound( "sound4.mp3" ) local soundsTable = {sound1, sound2, sound3, sound4} initialElements = #soundsTable local playRandom playRandom = function () if( #soundsTable == 0 ) then return elseif (#soundsTable == initialElements/2) then local randomAdvertising= math.random(1,#advertisingTable) audio.play (advertisingTable[randomAdvertising]) end local randomSound= math.random(1,#soundsTable) audio.play (soundsTable[randomSound], { onComplete = playRandom } ) table.remove ( soundsTable, randomSound ) end playRandom()

I need what you know  about the sounds (now i put 4, you will know why…) cause i want that in the exactly middle of the iterations sounds, play a random advertising sound, and then continue in with the sounds left…

In the code i did, as you can see, this works perfect… but i have one problem… the random advertising sound, playing in the correct position, but doesn’t wait anyone… and i can hear the advertising sound a the same time that the position 3 sound… you understand me?