Skip to content

AceEvent-3.0

embeddable This library can be embedded into your addon as a mixin; list it when you create the addon and its methods become available directly on your addon object (via self).
Creating an addon object →

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
end

Specify 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)
    -- ...
end

Inter-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

ParameterTypeDefaultDescription
targettableTarget object to embed AceEvent in.

Returns

TypeDescription
tableThe 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

ParameterTypeDefaultDescription
eventstringThe event to register for.
callback (optional)funcref | methodnameThe callback function to call when the event is triggered (defaults to a method with the event name).
arg (optional)anyAn optional argument to pass to the callback function.

Example

lua
function MyAddon:OnEnable()
    self:RegisterEvent("BAG_UPDATE", "UpdateBags")
end

function MyAddon:UpdateBags(event, bagID)
    -- ...
end

RegisterMessage

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

ParameterTypeDefaultDescription
messagestringThe message to register for.
callback (optional)funcref | methodnameThe callback function to call when the message is triggered (defaults to a method with the event name).
arg (optional)anyAn 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

ParameterTypeDefaultDescription
messagestringThe message to send.
...anyAny arguments to the message.

Example

lua
function MyAddon:SetFontSize(size)
    self:SendMessage("MyAddon_ConfigChanged", "fontSize", size)
end

UnregisterEvent

method#
lua
AceEvent:UnregisterEvent(event)

Unregister an event.

Parameters

ParameterTypeDefaultDescription
eventstringThe event to unregister.

UnregisterMessage

method#
lua
AceEvent:UnregisterMessage(message)

Unregister a message.

Parameters

ParameterTypeDefaultDescription
messagestringThe 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()
end

UnregisterAllMessages

method#
lua
AceEvent:UnregisterAllMessages()

Unregister all messages registered by this addon object (or custom "self").

Example

lua
function MyAddon:OnDisable()
    self:UnregisterAllMessages()
end

Ace3, a World of Warcraft addon framework.