
Error when default music list is empty and no custom song defined
Lyghfe opened this issue · 4 comments
Describe the bug
After entering the world, when I try to mount on anything other than the mounts I assigned a custom song to (didn't try the OG bird mounts that are supposed to work by default like riding cranes and such), Chocobo will have this lua error and won't work until I reload and it remount on only mounts that I assigned.
Lua Error:
Message: Interface/AddOns/Chocobo/Chocobo.lua:359: bad argument #1 to 'random' (interval is empty)
Time: Mon Sep 2 04:20:39 2024
Count: 1
Stack: Interface/AddOns/Chocobo/Chocobo.lua:359: bad argument #1 to 'random' (interval is empty)
[string "@Interface/AddOns/Chocobo/Chocobo.lua"]:359: in function PlayRandomMusic'
[string "@Interface/AddOns/Chocobo/Chocobo.lua"]:224: in function CheckMount'
[string "@Interface/AddOns/Chocobo/Chocobo.lua"]:187: in function <Interface/AddOns/Chocobo/Chocobo.lua:187>
Locals: self = <table> {
Mounted = true
Loaded = true
Events = <table> {
}
Frame = Frame {
}
Songs = <table> {
}
SoundControl = <table> {
}
CustomSongPanel = <table> {
}
Options = <table> {
}
Command = <table> {
}
Version = "v4.10.9"
Global = <table> {
}
MusicDir = "Interface\AddOns\Chocobo\music\"
Mounts = <table> {
}
Name = "Chocobo"
Running = true
}
mount = nil
nowPlaying = nil
To Reproduce
Steps to reproduce the behavior:
- Try mounting on anything that doesn't have a song defined I guess? Otherwise I wouldn't know
Expected behavior
Shouldn't "crash" the addon
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information)
- OS: Win 10
- WoW version/patch: 11.0.2
- WoW branch: retail
- AddOn version: v4.10.9
- Are you using a nolibs download of the AddOn? No, I downloaded this addon via Curseforge launcher and havent seen anything hinting on it being nolibs (https://www.curseforge.com/wow/addons/chocobo) also libs folder contains 22.7kb of data
Additional context
I again don't assume its all the addons fault and something might be faulty on my end as well but I couldn't find anything even after reinstalling chocobo and only having it run by itself. I also think that when it results in an error, that something happens with the background music - dunno if its playing the actual zone song or something random but I do notice it starting primarily after crash - might be me tripping tho, because I am anticipating something to happen
Will you be working to fix this problem yourself in a PR?
I asked ChatGPT to help me out to at least have an error thrown to show what went wrong and to also handle the error in a way that would allow the addon to still be running - it added this snippet:
function C:PlayRandomMusic(mount)
if mount then
self:PlayMusic(mount, true)
else
-- Check if the music table is empty
if #self.Global["MUSIC"] == 0 then
self:ErrorMsg("Music list is empty, cannot play random music.")
return
end
local id = math.random(1, #self.Global["MUSIC"])
if self.Global["PREVENTDUPE"] and #self.Global["MUSIC"] > 1 then
local name = self.Global["MUSIC"][id]
while name == nowPlaying do
id = math.random(1, #self.Global["MUSIC"])
name = self.Global["MUSIC"][id]
end
end
self:PlayMusic(id)
end
end
or as explained by itself:
The main issue was the potential for an empty music list leading to an invalid call to 'math.random'. By adding a check to ensure that the list is not empty before trying to select a random song, the error should be resolved.
Which works for now but I don't want to rely on a band aid that I don't fully understand. Hope this is somewhat of help and I'm looking forward to (hopefully) your next patch :D
Hm, that should only happen if the music list (the regular one, not the one specific to mounts) is empty. A check for that is missing when playing music.
Are you emptying the normal music list and using only the feature with custom songs per mount?
"Are you emptying the normal music list and using only the feature with custom songs per mount?"
Spot on, that's been the issue!
I didn't want the chocobo song playing in any case at all, so I thought going the extra mile of not only disabling but also removing them to prevent any instance of unwanted music, would do the trick. Turns out it bricked the addon.
I didn't think it was something like this causing the problem so I straight up deleted those from their list and didn't make the connection of ChatGPT telling me that the range for random music was 'empty' effectively meaning this list needs entries.
So then: re-downloading also did nothing for me cuz it saved the variables of the addon and saved that I emptied the list - so its excluding them by default now.
So then: re-downloading also did nothing for me cuz it saved the variables of the addon and saved that I emptied the list - so its excluding them by default now.
You should be able to use the "Reset" button to bring back the default list of songs.
In any case, I should probably add a check there so that if the list is empty, it just plays nothing if there's no custom song for the mount configured.