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.
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.
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 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()
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.
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…
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?
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.
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.
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 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()
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.
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…
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?