Hey there, I plan on making a playlist which plays random background music all the time. Here is the code written in main.lua:
--music algorithm local function onSystemEvent( event ) local eventType = event.type if ( eventType == "applicationStart" ) then --occurs when the application is launched and all code in "main.lua" is executed print("success?") playlist = { "e.ogg", "foria.ogg" } randomTrack = math.random( 1,2 ) if randomTrack == 1 then --e.ogg lasts for around 318 000 ms audio.play( audio.loadStream( "e.ogg" ) ) timer.performWithDelay( 318000, function() randomTrack = 2 end ) end if randomTrack == 2 then audio.play( audio.loadStream( "foria.ogg" ) ) --foria.ogg lasts for around 278 000 ms timer.performWithDelay( 278000, function() randomTrack = 1 end ) end end end Runtime:addEventListener( "system", onSystemEvent )
When I start the game, a random track is played, which is good. However, when that track finishes, no other track plays afterwards. I find it weird because I’m convinced that the game logic is flawless (apparently it isn’t). Really hope someone could guide me to the solution.
Thanks, Joe
(note: ignore the “print(“success”)” used just for testing purposes)