Quantcast
ESOUI - View Single Post - Updating stuff on the Wiki
View Single Post
04/13/14, 12:00 PM   #17
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 651
/sigh...

RegisterForEvent is a method defined to the EVENT_MANAGER object. It takes three parameters, the unique identifier for the addon that wants to watch for the event, the event code to watch for, and the function to call when the event fires.

(Optionally, the metatable for CreateControl also adds the RegisterForEvent method to the userdata table of controls that are created. So you could also do MyFrame:RegisterForEvent(eventCode, function) instead of going through EVENT_MANAGER.)

The RegisterForEvent method on EVENT_MANAGER works like this.
Addon A wants me to watch for event B and call function C when event B fires.
Event B fired! I will now send confirmation to Addon A that it was event B that fired, along with all returns from event B that the addon would be looking for.
eventFired = eventCodeB
eventReturns = ...
functionC(eventFired, ...)
The reason WHY the event handler (RegisterForEvent) passes along the event code is this:
Addon A wants me to watch for event B and call function C when event B fires.
Addon A wants me to watch for event D and call function C when event D fires.
Addon A wants me to watch for event E and call function C when event E fires.
Event D fired! I will now send confirmation to Addon A that it was event D that fired, along with all returns from event D that the addon would be looking for.
eventFired = eventCodeD
eventReturns = ...
functionC(eventFired, ...)
This does not make the eventCode part of the the returns list for the event. The event handler takes the event code and prepends it on to the list of returns from the event before sending that along to the function.
  Reply With Quote