Skip to content

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.

  • component A instance of YaComponent, such as YaMoverComponent

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.

  • component A instance of YaComponent, such as YaMoverComponent

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.

  • component A instance of YaComponent, such as YaMoverComponent
  • arguments The event arguments.

Code sample

The following code sample registers an event handler which deregisters itself in the StartEvent event of YaMoverComponent.

1
2
3
4
5
6
7
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)