Thread Tools Display Modes
Prev Previous Post   Next Post Next
Yesterday, 06:31 PM   #1
entr0py42
Join Date: Jul 2024
Posts: 1
Cannot initialize my addon

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:
  1. local ADDON_NAME = "SimpleFarmTrack"
  2. SimpleFarmTrack = {}
  3. local async = LibAsync
  4.  
  5.  
  6. local function GetItemPrice(itemLink)
  7.     local price = LibPrice.ItemLinkToPriceGold(itemLink)
  8.     if (price == nil or price == 0) then price = GetItemLinkValue(itemLink, true) end
  9.     return price
  10. end
  11.  
  12.  
  13. local total = 0
  14. function SimpleFarmTrack:OnItemLoot(eventCode, name, itemLink, quantity)
  15.   total = total + GetItemPrice(itemLink) * quantity
  16.   SimpleFarmTrackLabel:SetText(string.format("%.2f",total))
  17. end
  18.  
  19. function SimpleFarmTrack:AddEventHandlers()
  20.   EVENT_MANAGER:RegisterForEvent(
  21.     ADDON_NAME,
  22.     EVENT_LOOT_RECEIVED,
  23.     function(...)
  24.       async:Call(self:OnItemLoot(...))
  25.     end
  26.   )
  27. end
  28.  
  29. function SimpleFarmTrack:OnAddOnLoaded(event, addonName)
  30.   if addonName == ADDON_NAME then self:AddEventHandlers() end
  31. end
  32.  
  33. EVENT_MANAGER:RegisterForEvent(
  34.     ADDON_NAME,
  35.     EVENT_ADD_ON_LOADED,
  36.     function(...)
  37.       SimpleFarmTrack:OnAddOnLoaded(...)
  38.     end
  39. )


If I remove the entire EVENT_MANAGER part at the end and replace it with
Lua Code:
  1. SimpleFarmTrack:AddEventHandlers()
it works.

Last edited by entr0py42 : Yesterday at 06:55 PM. Reason: discovered some workaround
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » Cannot initialize my addon


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off