Appearance
AceEvent-3.0
AceEvent-3.0 provides event registration and secure dispatching. All dispatching is done using CallbackHandler-1.0. AceEvent is a simple wrapper around CallbackHandler, and dispatches all game events or addon message to the registrees.
Usage
Subscribing to events
lua
MyAddon:RegisterEvent("NAME_OF_EVENT")
function MyAddon:NAME_OF_EVENT()
-- process the event
endSpecify a handler method/function instead of the default name:
lua
MyAddon:RegisterEvent("NAME_OF_EVENT", "MyHandlerMethod")
MyAddon:RegisterEvent("NAME_OF_OTHER_EVENT", function() doSomethingSpiffy() end)The first argument to a handler is always the event name, then the event's own arguments:
lua
function MyAddon:NAME_OF_EVENT(eventName, arg1, arg2, arg3)
-- ...
endInter-addon messages
Messages work like events but are fired by addons rather than the client:
lua
MyAddon:RegisterMessage("NAME_OF_MESSAGE")
MyAddon:SendMessage("NAME_OF_MESSAGE")
MyAddon:SendMessage("NAME_OF_OTHER_MESSAGE", arg1, arg2)Messages are local to the client. To talk between players' addons, use AceComm.
API Reference
Embed
method#
lua
AceEvent:Embed(target)Copies AceEvent's methods onto target so you can call them on it directly. See The :Embed method.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
target | table | Target object to embed AceEvent in. |
Returns
| Type | Description |
|---|---|
table | The target object that was embedded. |
RegisterEvent
method#
lua
AceEvent:RegisterEvent(event, callback?, arg?)Register for a Blizzard Event.
The callback will be called with the optional arg as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied). Any arguments to the event will be passed on after that.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
event | string | The event to register for. | |
callback (optional) | funcref | methodname | The callback function to call when the event is triggered (defaults to a method with the event name). | |
arg (optional) | any | An optional argument to pass to the callback function. |
Example
lua
function MyAddon:OnEnable()
self:RegisterEvent("BAG_UPDATE", "UpdateBags")
end
function MyAddon:UpdateBags(event, bagID)
-- ...
endRegisterMessage
method#
lua
AceEvent:RegisterMessage(message, callback?, arg?)Register for a custom AceEvent-internal message.
The callback will be called with the optional arg as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied). Any arguments to the event will be passed on after that.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
message | string | The message to register for. | |
callback (optional) | funcref | methodname | The callback function to call when the message is triggered (defaults to a method with the event name). | |
arg (optional) | any | An optional argument to pass to the callback function. |
SendMessage
method#
lua
AceEvent:SendMessage(message, ...)Send a message over the AceEvent-3.0 internal message system to other addons registered for this message.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
message | string | The message to send. | |
... | any | Any arguments to the message. |
Example
lua
function MyAddon:SetFontSize(size)
self:SendMessage("MyAddon_ConfigChanged", "fontSize", size)
endUnregisterEvent
method#
lua
AceEvent:UnregisterEvent(event)Unregister an event.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
event | string | The event to unregister. |
UnregisterMessage
method#
lua
AceEvent:UnregisterMessage(message)Unregister a message.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
message | string | The message to unregister. |
UnregisterAllEvents
method#
lua
AceEvent:UnregisterAllEvents()Unregister all events registered by this addon object (or custom "self").
Example
lua
function MyAddon:OnDisable()
self:UnregisterAllEvents()
endUnregisterAllMessages
method#
lua
AceEvent:UnregisterAllMessages()Unregister all messages registered by this addon object (or custom "self").
Example
lua
function MyAddon:OnDisable()
self:UnregisterAllMessages()
end