#0 - April 12, 2007, 11:46 a.m.
By sub-table, I mean something to the effect of Foo.Bar = {} (where Bar is the sub-table of Foo).
The following should help to demonstrate this bug:
Addon.toc
## Interface: 20003
## Title: My Addon
## SavedVariables: Foo.Bar
Addon.lua
Addon.lua
if not Foo then Foo = {}; end
Foo.LoadAddon = function()
if not Foo.Bar then Foo.Bar = {}; end
Foo.Bar.TestVar = "Test me!"
end
Foo.OnEvent = function()
if event == "ADDON_LOADED" and arg1 == "Addon" then
Foo.LoadAddon()
end
end
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", Foo.OnEvent)
frame:RegisterEvent("ADDON_LOADED")
Reload the UI to load the newly-created saved variables file:
SavedVariables\Addon.lua
Foo.Bar = nil
And, finally, the error message is revealed:
WTF\Account\<Name>\SavedVariables\Addon.lua:2: attempt to index global 'Foo' (a nil value)
The problem is that the saved variables script is trying to create Foo.Bar when Foo doesn't yet exist (it's nil). So when creating this file, it'll need to look through and create the other tables.
Foo = {
Bar = nil
}
And then a more complicated structure like Addon.Table.Something.Else would be:
Addon = {
Table = {
Something = {
Else = nil
}
}
}