BankNorris, thank you for the suggestion. I do have a table length nil value error, and while I can guess which table (the global saved vars), I am unsure why. What follows is the error and my full code. Line 64 is the first line in OnEnable.
You will notice I have a debug function, and the GIIS exit check is less prone to endless loops.
Error:
Code:
1x FollowerRetrainer\Retrainer.lua:64: attempt to get length of field '?' (a nil value)
FollowerRetrainer\Retrainer.lua:64: in function <FollowerRetrainer\Retrainer.lua:63>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
Ace3\AceAddon-3.0\AceAddon-3.0-12.lua:558: in function `EnableAddon'
Ace3\AceAddon-3.0\AceAddon-3.0-12.lua:651: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:636>
[C]: ?
[C]: in function `LoadAddOn'
FrameXML\UIParent.lua:336: in function `UIParentLoadAddOn'
FrameXML\UIParent.lua:359: in function `CombatLog_LoadUI'
FrameXML\UIParent.lua:906: in function <FrameXML\UIParent.lua:814>
Locals:
nil
Full code:
Code:
local retrainer = LibStub("AceAddon-3.0"):NewAddon("FollowerRetrainer", "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("FollowerRetrainer", true)
-- extra libs
local LBU = LibStub("LibBagUtils-1.0")
local LDB = LibStub("LibDataBroker-1.1")
-- retraining items
local retraining_item_ids = {
[118354] = true, -- Follower Retraining Certificate
[122273] = true, -- Follower Trait Retraining Guide
[122272] = true, -- Follower Ability Retraining Manual
[118475] = true, -- Hearthstone Strategy Guide
[118474] = true, -- Supreme Manual of Dance
[122584] = true, -- Winning with Wildlings
[122583] = true, -- Grease Monkey Guide
[122582] = true, -- Guide to Arakkoa Relations
[122580] = true, -- Ogre Buddy Handbook
[122275] = true, -- Sun-touched Feather of Rukhmar
}
local scroll_case_id = 123858 -- Follower Retraining Scroll Case
-- db for altering profiles
local db
-- default saved variables
local defaults = {
profile = {
enabled = true,
selfDebug = false,
--@debug@
selfDebug = true,
--@end-debug@
},
char = {
safeRetraining = true,
}
}
function retrainer:Debug(str, ...)
if not self.db.profile.debugMode then return end
if not str or strlen(str) == 0 then return end
if select("#", ...) > 0 then
if strfind(str, "%%[dfqsx%d]") or strfind(str, "%%%.%d") then
str = format(str, ...)
else
str = strjoin(" ", str, tostringall(...))
end
end
DEFAULT_CHAT_FRAME:AddMessage(format("|cffff9933%s:|r %s", self.name, str))
end
function retrainer:OnInitialize()
-- register saved variables with AceDB
db = LibStub("AceDB-3.0"):New("FollowerRetrainerDB", defaults, true)
db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
self.db = db
self:SetEnabledState(self.db.profile.enabled)
end
function retrainer:OnEnable()
if #self.db.global[cached_items] < #retraining_item_ids or not self.db.global[cached_case] then
self:RegisterEvent("GET_ITEM_INFO_RECEIVED")
end
-- global saved variables complete,
-- sort the items alphabetically per client locale
table.sort(self.db.global[cached_items], function(a, b)
return a.name < b.name
end)
if self.db.profile.selfDebug then
for i = 1, #self.db.global[cached_items] do
self:Debug("Debugging the global variables: ", tostring(self.db.global[i]))
end
self:Debug("And the scroll case: ", tostring(self.db.global[scroll_case]))
end
end
function retrainer:OnDisable()
end
function retrainer:RefreshConfig()
db = self.db
end
function retrainer:GET_ITEM_INFO_RECEIVED(...)
if (#self.db.global[cached_items] >= #retraining_item_ids) and (self.db.global[scroll_case]) then
self:UnregisterEvent("GET_ITEM_INFO_RECEIVED")
return
end
local item_id = ...
local item = GetItemInfo(item_id)
if retraining_item_ids[item_id] then
table.insert(self.db.global[cached_items], item)
elseif item_id == scroll_case_id then
table.insert(self.db.global[cached_case], item)
end
end