Siegh
Thronar Developer
Hello! I'm trying to have my client play random songs from a list in a loop but, while I do manage to make it randomize songs from a list and keep playing as a loop, as soon as it chooses one music it will stick with it indefinitely.
How can I have it randomize its pick after a song plays entirely?
This is on client.lua:
How can I have it randomize its pick after a song plays entirely?
This is on client.lua:
LUA:
local musicTracks = {
"/sounds/startup",
"/sounds/townMusic1",
"/sounds/townMusic2",
--"/sounds/dungeonMusic1",
--"/sounds/dungeonMusic2",
}
local randomTrack = musicTracks[math.random(1,#musicTracks)]
function startup()
if musicChannel then
musicChannel:enqueue(musicTracks[math.random(1,#musicTracks)], 3)
connect(g_game, {
onGameStart = function()
musicChannel:stop(3)
local currentMusic = musicChannel:enqueue(musicTracks[math.random(1,#musicTracks)], 3)
if currentMusic then
currentMusic.onFinish = function()
-- Recursive call to pick and play the next random song
musicChannel:stop(3)
musicChannel:enqueue(musicTracks[math.random(1,#musicTracks)], 3)
end
end
end
})
connect(g_game, {
onGameEnd = function()
musicChannel:stop(3)
local currentMusic = musicChannel:enqueue(musicTracks[math.random(1,#musicTracks)], 3)
if currentMusic then
currentMusic.onFinish = function()
-- Recursive call to pick and play the next random song
musicChannel:stop(3)
musicChannel:enqueue(musicTracks[math.random(1,#musicTracks)], 3)
end
end
end
})
end