Events

The Events module provides mechanisms to manage event-driven programming by allowing registration of functions that respond to specific event types through on for persistent listeners and once for single-use listeners, with the ability to deregister these listeners using off, making it suitable for applications requiring dynamic and responsive interaction with different systems or user-generated events.

Usage

To use this module, add the following require at the top of your script:

local Events = require 'engine/events'

Reference

events.on(eventtype, func)

Start listening to events of a certain type. This method will take an event type and a function to call if the


event is triggered.

Parameters:
  • eventtype (str) – Type of the event. See possible types of events below

  • func (function) – function to call

events.once(eventtype, func)

Listen to the next event of a certain type. After the event is triggered once, the event listener will automatically


deactivate again. This method will take an event type and a function to call if the event is triggered.

Parameters:
  • eventtype (str) – Type of the event. See possible types of events below

  • func (function) – function to call

events.off(eventtype)

Stop listening to events of a certain type.

Parameters:

eventtype (str) – Type of the event

Examples

For examples and more information, see Handling Events