ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   ESO event registration (https://www.esoui.com/forums/showthread.php?t=723)

belialamiee 04/09/14 05:50 AM

ESO event registration
 
Hi Guys,

I am struggling with something that is probably fundamentally easy.

I have written a quick addon that prints xp to screen. at present it is triggering on update. obviously this is not optimal. So i want it to only update on xp gain.

But I can't seem to get the event to actually work.

here is my current code.

Code:

local curXP = GetUnitXP("Player")
local maxXP = GetUnitXPMax("Player")


function OnUpdate()
    MahaliaXpgain:SetText(string.format("XP: %d/%d", curXP, maxXP))

end

function UpdateXP()
curXP = GetUnitXP("Player")
maxXP = GetUnitXPMax("Player")
OnUpdate()
end

--this was bastardised from yout tutorial at http://wiki.esoui.com/AddOn_Quick_Questions#How_do_events_work.3F
function Mahalia_OnInitialized(self)
    --Register on the top level control...
    self:RegisterForEvent(EVENT_EXPERIENCE_GAINED, UpdateXP)
 
    --OR, register with a string unique to your add-on
    EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAINED, UpdateXP)
end

I can have it trigger by using
Code:

<OnMouseDown>
                UpdateXP()
 </OnMouseDown>

But I can't just seem to get the event to trigger UpdateXP() even when it is was just d("print me") it woudn't trigger on xpgain

What am i doing wrong with event registration?

Xrystal 04/09/14 06:09 AM

You have

EVENT_EXPERIENCE_GAIN (integer value, integer reason)
EVENT_EXPERIENCE_GAIN_DISCOVERY (string areaName, integer value)
EVENT_EXPERIENCE_UPDATE (string unitTag, integer currentExp, integer maxExp, integer reason)

The Update one occurs when someone levels in your vicinity.

The calling function you are using right but the function being used isn't being utilised properly.

Lua Code:
  1. local function UpdateXP(eventID,value,reason)
  2.      CHAT_SYSTEM:AddMessage(string.format("You have gained %d experience.",value))
  3. end
  4.  
  5. local function UpdateXPDiscovery(eventID,areaName,value)
  6.     CHAT_SYSTEM:AddMessage(string.format("You have gained %d experience through discovering %s",value,areaName))
  7. end
  8.  
  9. EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAIN, UpdateXP)
  10. EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAIN_DISCOVERY, UpdateXPDiscovery)

As you can see the eventID is needed in the function you use to process the event. Some events are still to have their parameters discovered but they always have the eventID as their first parameter.

I also notice that you had it as GAINED rather than GAIN. Quite understandable.

belialamiee 04/09/14 06:31 AM

Thank you so much

really appreciate your help

worked a charm


All times are GMT -6. The time now is 04:12 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI