Thread Tools Display Modes
06/04/14, 10:36 PM   #1
jtsmith1287
Join Date: Mar 2014
Posts: 1
Assistance needed for registering events

So, I'm learning lua and the ESO API. I had an idea for a super simple addon, but getting just the basics down is proving to be a nightmare for me. I'm going to (embarrassingly) paste my code and ask that you guys tell me where I'm going wrong. What I'm looking to accomplish is getting the information of the items I'm looting, but I can't even get the dang loot event registered. And excuse the weird variable names--lots of poking and testing has been going on, as well as changing my addon idea a few times after learning of API restrictions. That and some of this is pasted examples from the esoui wiki.

When I gain loot, I want to see these items printed into chat via d() or something so I can start figuring this out. Thanks in advance for the help.

PileOMobs.lua
Code:
function lootReceived(receivedBy, itemName, quantity, itemSound, lootType, self)

  Loot:SetText("You looted stuff!!!")
  d(itemName)

  end
  
function RegisterLootEvent(eventcode, name)

  if (name == "PileOMobs") then
    PileOMobs:RegisterForEvent(EVENT_LOOT_RECEIVED, lootReceived)
    Loot:SetText("Loot event registered.")
    end

  end

function PileOMobsInit()

  EVENT_MANAGER:RegisterForEvent("PileOMobs", EVENT_ADD_ON_LOADED, RegisterLootEvent)

  end

PileOMobs.xml
Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="Whatever">
            <Dimensions x="250" y="80" />
            <Anchor point="RIGHT" />

            <OnInitialized>
                PileOMobsInit()
            </OnInitialized>
 
            <Controls>
                <Label name="Loot" font="ZoFontGame" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="TOP" text="Got yerself a errawr">
                    <AnchorFill />
                </Label>
            </Controls>
        </TopLevelControl>
    </Controls>
</GuiXml>
  Reply With Quote
06/05/14, 01:31 AM   #2
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
A good practice is to prefix your public function with the addon name. You will avoid few kinds of conflict. As example :
PileOMobs.lootReceived
I also saw with a :, instead the dot.


And i think you missed a name on the second, and got a wrong controller.
PileOMobs:RegisterForEvent(EVENT_LOOT_RECEIVED, lootReceived)

Try to type it like the first, what will be like :
EVENT_MANAGER:RegisterForEvent("PileOMobs", EVENT_LOOT_RECEIVED, lootReceived)

Last edited by Tar000un : 06/05/14 at 01:33 AM.
  Reply With Quote
06/05/14, 01:34 AM   #3
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
You're almost there but but not quite got it right.

Give this slight change a go

Lua Code:
  1. local function lootReceived(eventCode,receivedBy, itemName, quantity, itemSound, lootType, self)
  2.   Loot:SetText("You looted stuff!!!")
  3.   d(itemName)
  4. end
  5.  
  6. local function RegisterLootEvent(eventcode, name)
  7.   if (name == "PileOMobs") then
  8.     EVENT_MANAGER:RegisterForEvent("PileOMobs",EVENT_LOOT_RECEIVED, lootReceived)
  9.     Loot:SetText("Loot event registered.")   --- Note: Message probably won't appear at this stage
  10.   end
  11. end
  12.  
  13. function PileOMobsInit(self)
  14.   self:RegisterForEvent("PileOMobs", EVENT_ADD_ON_LOADED, RegisterLootEvent)
  15. end
  Reply With Quote
06/06/14, 02:01 PM   #4
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Originally Posted by Tar000un View Post
I also saw with a :, instead the dot.
In Lua, using the colon ( : ) instead of the dot makes a variable "self" available in the function.

For example:
Lua Code:
  1. local foo = {}
  2. foo.val = 1
  3.  
  4. function foo:bar()
  5.     d(self.val) --Prints 1
  6. end

When you fully define the tables, it's not as critical, since you can simply use the table name instead:
Lua Code:
  1. function foo.bar()
  2.     d(foo.val) --Prints 1
  3. end

Where it's most useful is object-oriented programming style, where you have the same function with different objects and need self to differentiate between them.
  Reply With Quote
06/07/14, 01:58 AM   #5
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Thanks for the enlightenment !
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Assistance needed for registering events


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