Maintenance for the week of February 18:
• [COMPLETE] Xbox One: EU megaserver for maintenance – February 20, 4:00AM EST (9:00 UTC) - 12:00PM EST (17:00 UTC)
The Wrathstone DLC Game Pack and Update 21 base game patch are now available to test on the PTS! Read the full patch notes here: https://forums.elderscrollsonline.com/en/discussion/454456/

How to handle Events?

nonsolitarymanb16_ESO
nonsolitarymanb16_ESO
Soul Shriven
Hello,

I've learned some basics of LUA and wanted to go deeper into add ons (I can write a very basic one, like the example at esoui) but I have no clue how to handle Events. I used the esoui wiki but that doesn't really help me concerning events - it's not as beginner friendly as it should be (imho).

I used the example code there for the group invite add on and changed the event with another but it doesn't work. The starter guide for an Add-On is pretty nice and clear (http://wiki.esoui.com/MyFirstAddon_tutorial) but as u can see, there a no events in this guide. So could anyone tell me what exactly I need to do to fire a function when an event is triggered?
The event I am currently focused at is the "EVENT_PLAYER_COMBAT_STATE"
Edited by nonsolitarymanb16_ESO on April 11, 2014 5:51PM
  • BlackTinuviel
    If you look at events on the esoui wiki (http://wiki.esoui.com/Events), this shows you want parameters your delegate function needs to handle for any events that need something different than the default.
  • claudekennilol
    claudekennilol
    ✭✭✭
    Every event returns first an event id, then the parameters listed in BlackTinuviel's link

    So specifically
    EVENT_PLAYER_COMBAT_STATE

    to hand that event you'd need to register a method that has the parameters eventid and inCombat

    (the name doesn't have to match the parameter name listed, but it's probably better to do so just for sanity's sake)
  • Seerah
    Seerah
    ✭✭✭
    I wrote this up for someone last night - I may as well post it here, too.
    http://pastebin.com/FAY5HFMD
    Author & Moderator at ESOUI
    My Addons
  • claudekennilol
    claudekennilol
    ✭✭✭
    Seerah wrote: »
    I wrote this up for someone last night - I may as well post it here, too.
    http://pastebin.com/FAY5HFMD

    Maybe I was doing something wrong, but in my limited foray into LUA last night, I couldn't register a local method to the EVENT_ADD_ON_LOADED event.

    edit: or rather I could register it, but it just errored as soon as it loaded which nets to me being "unable to"
    Edited by claudekennilol on April 11, 2014 6:27PM
  • Seerah
    Seerah
    ✭✭✭
    You were probably doing something wrong then. ;) You have to define the function before assigning it. Otherwise, it doesn't exist yet.
    Author & Moderator at ESOUI
    My Addons
  • claudekennilol
    claudekennilol
    ✭✭✭
    That was probably it, then. Thanks. I'll keep that in mind when I head back into it tonight.
  • nonsolitarymanb16_ESO
    nonsolitarymanb16_ESO
    Soul Shriven
    I know the event site of esoui. As I said, I used it but it isn't still clear to me. I'll post you an example.
    local function OnCombatMode(eventCode, inCombat)
        --print the inviter's name to chat
        d('bla'..inCombat)
    end
    
    function MyAddOn_OnInitialized(self)
    	self:RegisterForEvent(EVENT_PLAYER_COMBAT_STATE, OnCombatMode)
    end
    

    This isn't working. I initialize the "myAddon_OnInitialized" function simply with "MyAddOn_OnInitialized()". That returns an error. Actually it's kinda understandable. But even without it, it won't work and return an error. Why? I mean.. the event should trigger the function. So how is it supposed to work when it's inside a function wich is triggered by... nothing?!

    It's the same syntax as posted on esoui http://wiki.esoui.com/AddOn_Quick_Questions#How_do_events_work.3F
    Edited by nonsolitarymanb16_ESO on April 12, 2014 10:10AM
  • Seerah
    Seerah
    ✭✭✭
    So... don't put it in a function?

    If that's your whole code, you have a) nothing to call the MyAddOn_OnInitialized function, and b) nothing to pass through as the self argument. Of course you're getting an error. ;)

    Read through the pastey I posted above.
    Edited by Seerah on April 12, 2014 4:40PM
    Author & Moderator at ESOUI
    My Addons
  • nonsolitarymanb16_ESO
    nonsolitarymanb16_ESO
    Soul Shriven
    As I wrote. Even without the function it won't work. And your code isn't helpful in that way because it seems to be some kind of constructer? It's a function that is inilizied when the add on is startet but not when an event is fired at some time, or am I wrong?

    Could u write a sample code wich prints out "blubb" or something when the combat event is fired? Because the code above is definitly not (!) working.
    Edited by nonsolitarymanb16_ESO on April 12, 2014 7:24PM
  • Aiiane
    Aiiane
    ✭✭✭
    local function OnCombatMode(eventCode, inCombat)
        if inCombat then d("Entering combat...") else d("Leaving combat") end
    end
    EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_PLAYER_COMBAT_STATE, OnCombatMode)
    

    Always use EVENT_MANAGER for global (non-UI-related) events.
    Edited by Aiiane on April 12, 2014 7:37PM
    Aiiane, Aldmeri Dominion, Auriel's Bow, NA ☆ Twitter
  • nonsolitarymanb16_ESO
    nonsolitarymanb16_ESO
    Soul Shriven
    Thank u very much. Now I get it (I hope so xD) :)
    Edited by nonsolitarymanb16_ESO on April 12, 2014 7:46PM
Sign In or Register to comment.