Hi all,
I'm trying to get into creating addons. I'm working on an addon that displays the total value of the items you've picked.
No matter what I try, I cannot initialize it. I've tried several approaches and inspected a few addons to understand how they do it. I think the problem is OOP related.
The error I get:
Code:
user:/AddOns/SimpleFarmTrack/SimpleFarmTrack.lua:37: function expected instead of nil
stack traceback:
user:/AddOns/SimpleFarmTrack/SimpleFarmTrack.lua:37: in function '(anonymous)'
The code:
Lua Code:
local ADDON_NAME = "SimpleFarmTrack"
SimpleFarmTrack = {}
local async = LibAsync
local function GetItemPrice(itemLink)
local price = LibPrice.ItemLinkToPriceGold(itemLink)
if (price == nil or price == 0) then price = GetItemLinkValue(itemLink, true) end
return price
end
local total = 0
function SimpleFarmTrack:OnItemLoot(eventCode, name, itemLink, quantity)
total = total + GetItemPrice(itemLink) * quantity
SimpleFarmTrackLabel:SetText(string.format("%.2f",total))
end
function SimpleFarmTrack:AddEventHandlers()
EVENT_MANAGER:RegisterForEvent(
ADDON_NAME,
EVENT_LOOT_RECEIVED,
function(...)
async:Call(self:OnItemLoot(...))
end
)
end
function SimpleFarmTrack:OnAddOnLoaded(event, addonName)
if addonName == ADDON_NAME then self:AddEventHandlers() end
end
EVENT_MANAGER:RegisterForEvent(
ADDON_NAME,
EVENT_ADD_ON_LOADED,
function(...)
SimpleFarmTrack:OnAddOnLoaded(...)
end
)
If I remove the entire EVENT_MANAGER part at the end and replace it with
Lua Code:
SimpleFarmTrack:AddEventHandlers()
it works.