EventHelper
EventHelper is a global object that registers event handlers in events.Functions
void EventHelper.AddListener(table component, string eventName, function handler)
Adds a handler to the component object for the eventName event.
Note: only API components and objects with the AddListener function can be called.
componentA instance ofYaComponent , such asYaMoverComponent
void EventHelper.RemoveListener(table component, string eventName, function handler)
Removes the handler from the component object for the eventName event , which inverses the call of AddListener.
Note: only API components and objects with the RemoveListener function can be called.
componentA instance ofYaComponent , such asYaMoverComponent
void EventHelper.Emit(table component, string eventName, ... arguments)
Emits the eventName event from the component object with the following arguments.
Note: only API components and objects with the Emit function can be called.
componentA instance ofYaComponent , such asYaMoverComponent argumentsThe event arguments.
Code sample
The following code sample registers an event handler which deregisters itself in the StartEvent event of YaMoverComponent.
local mover = script:GetYaComponent("YaMoverComponent")
-- StartMoving has no arguments.
local function handler()
print('Start received')
EventHelper.RemoveListener(mover, "StartEvent", handler)
end
EventHelper.AddListener(mover, "StartEvent", handler)