View Single Post
12-26-14, 11:23 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by AnrDaemon View Post
Is there any documentation on the order of events firing? Or a library that may help managing accumulation and registration of event callbacks?
Registering for events is very simple and straightforward; you don't need a library to do it. If you're handling just a few events, just do an if/elseif chain in your frame's OnEvent script. If you're handling lots of events, you may want to factor out each event's handler into its own function:

Code:
local MyAddon = CreateFrame("Frame")
MyAddon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
MyAddon:RegisterEvent("SOME_EVENT_HERE")

function MyAddon:SOME_EVENT_HERE(some_arg, some_other_arg)
    -- Do stuff here
end
As for the order of events, there really isn't one, outside of the initial loading process. Events indicate that things have happened in the game, and there's no fixed order for what happens in the game -- you can gain a buff, enter combat or cast a spell at any time, and so can the players around you, etc.

Was there some specific aspect of event handling you're having trouble with?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote