It looks like you're new here. If you want to get involved, click one of these buttons!
local arabaudio1 = csv:getField(self.i, "audio1") local arabaudio2 = csv:getField(self.i, "audio2") local arabaudio3 = csv:getField(self.i, "audio3") if arabaudio1 ~= "null" then local sound1 = Sound.new("audio/"..arabaudio1..".ogg") local audio1 = sound1:play() if arabaudio2 ~= "null" then audio1:addEventListener(Event.COMPLETE, function() local sound2 = Sound.new("audio/"..arabaudio2..".ogg") local audio2 = sound2:play() if arabaudio3 ~= "null" then audio2:addEventListener(Event.COMPLETE, function() local sound3 = Sound.new("audio/"..arabaudio3..".ogg") local audio3 = sound3:play() end) end end) end end |
Comments
And I guess we can write it more elegantly using Lua coroutines (they're perfect for such purposes).
But if there're not many audios, I'd leave the code as it is.
P. S. We can't 'removeEventListener' with anonymous function:
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
I would be interested in a for loop implementation.
Could you please show me some sample code?
Or I can try myself really and come back!
Thank you for your advice apollo14.
https://www.lua.org/pil/9.1.html
http://lua-users.org/wiki/CoroutinesTutorial
https://www.tutorialspoint.com/lua/lua_coroutines.htm
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Peace.