GitHub page with download link
Usage isn't too complicated. It's nearly identical to the above link to what Vendetta does, with a couple things added or removed. Note that anything triggered gets processed immediately, there is no queue.
You can register (and unregister) an object to multiple events at once either via an array or just additional arguments to the Event.[Un]Register function.
Not everything has been tested extensively so I'd appreciate any bug reports.
I wrote this comment in the lua file:
Example usage with imaginary Cat and Mouse classes:
Code: Select all
-- create generic event handling function for a Cat class
function Cat:OnEvent(eventname, ...)
if eventname == "MOUSE_SPAWNED" and not self.chasing then
local mouse = ...
self:ChaseMouse(mouse)
end
end
-- use a regular function to process the event as well
function PrintWhenMouseSpawns(eventname, mouse)
print("MOUSE SPAWNED! "..tostring(mouse))
end
function Mouse:initialize(x, y)
self:Spawn(x, y)
Event.Trigger("MOUSE_SPAWNED", self) -- trigger the event and pass any arguments you want
end
-- register the Cat class and function we created with the MOUSE_SPAWNED event
Event.Register(Cat, "MOUSE_SPAWNED")
Event.Register(PrintWhenMouseSpawns, "MOUSE_SPAWNED")
If it is a table, then when the event it's associated with is triggered, it will
first look for a function of the same name as the event in the table, and if it
doesn't find one it will fall back to the table's "OnEvent" method, if it exists.