Allows you to register new event callbacks when initializing mods.
local Event = ELONA.require("core.Event")
register (event_id, handler[, opts]) | Registers a new event handler. |
unregister (event_id, handler) | Unregisters an event handler that was previously registered with
Event.register . |
trigger (event[, data][, opts]) | Triggers an event from a Lua script. |
Registers a new event handler.
This function will insert a new callback hander for the given event into the list of callback handlers for that event. Then, when the event is fired, each callback in the list will be run in the order in which they were registered. The callbacks will receive a single table argument containing the event's parameters. These parameters will differ between event types. Read the documentation for the event you're handling to see the available event arguments for it.
Optionally, a table of options can be passed. There are two
parameters supported. priority
determines the order
in which the callback will run, with higher values being given
priority. The default is 1000. instances
is a table
of objects that allow only running the event when certain instance
parameters are received by the event, like a specific character or
type. These parameters vary per event and not all events support
them.
A given callback can only be registered once per event/instance.
Parameters:local GUI = ELONA.require("core.GUI")
local Event = ELONA.require("core.Event")
local function my_chara_moved_handler(chara)
GUI.txt("The character " .. chara.name .. " is about to move. ")
end
Event.register("core.character_moved", my_chara_moved_handler, { priority = 1000 })
Unregisters an event handler that was previously registered with
Event.register
.
This has no effect if the handler was not already registered.
Parameters:Triggers an event from a Lua script.
You can pass a table of
options containing an instances
parameter to run
instanced events as well as the non-instanced version.
WARNING: This does not currently prevent infinite recursion!