I'm working on an Addon rewrite, basically turning the old addon Wtacher for WildStar into a newer version that's more easy to maintain due a new modular structure. The original author gave me permission for this, but told me to rewrite the addon to understand it better, as I'm quite new to this.
So the original Addon can be found here: http://www.curse.com/ws-addons/wildstar/221782-watcher
My source code can be found here: https://github.com/NekoNova/WatcherEx
The error message I am getting ingame is the following:
...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:1433: bad argument #1 to 'ipairs' (table expected, got nil) stack trace: [C]: in function 'ipairs' ...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:1433: in function 'FillFiltersList' ...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:886: in function <...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:867>
So I took a look at my source code at the mentioned lines, and basically this piece of code is causing problems:
-- Fills the list of Filters available to be used in the Addon.
function WatcherEx:FillFiltersList()
if self.wndMain == nil then
return
end
local filtersList = self.wndMain:FindChild("filters_list")
filtersList:DestroyChildren()
for i, filterClass in ipairs(self.tFilters) do
local filterItem = Apollo.LoadForm(self.xmlDoc, "filter_item", filtersList, self)
filterItem:SetData({ filter = filterClass })
filterItem:FindChild("name"):SetText(filterClass.name)
end
return filtersList:ArrangeChildrenVert()
end
So basically I try to use my internal tFilters variable, but it's nil and should be a table. As I said, I'm quite new to Lua programming for games, but from what I understand, I probably have something wrong set up in my __init metafunction, as I copied this from the original and tries to clean this a bit. This is code metatable code:
function WatcherEx:new(tObject)
tObject = tObject or {}
setmetatable(tObject, self)
self.__index = self
-- Initialization
self.tSettings = {}
self.tDefaults = {}
self.tAbilities = {}
self.tInnates = {}
self.tEngineerSpells = {}
self.tActiveRules = {}
local tClass = setmetatable({
__init = function(self)
self.tActiveRules = { }
self.bUnlockAll = false
self.eventsHidden = nil
self.tFilters = {
AvailabilityFilter,
TimeFilter,
CombatFilter,
ActionSetFilter,
SpecialFilter,
HPFilter,
MPFilter,
ShieldFilter,
ChargeFilter,
ResourcesFilter,
BuffFilter,
LuaFilter}
end,
__base = self,
__name = "WatcherEx"
}, {
__index = self,
__call = function(cls, ...)
local tTable = setmetatable({}, self)
cls.__init(tTable, ...)
return tTable
end})
self.__class = tClass
return tObject
end
Could someone tell me what I did wrong, and explain the problem? I'm trying to learn more about Lua, but this part about inheritance and metaclasses is a bit confusing.
EDIT: When I look at it now, I'm actually thinking I can cut out the metatable structure and just set the variables directly as members of my WatcherEx Table....
__initnever got called and so thetFilteris never set. Stick aprintin there to see if that's the case. A second guess is that the outterselfis different from the innerself. - greatwolf