Skip to content

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

__init

static __init()

__clear

static __clear()

on

static 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 (string): Type of the event. See possible types of events below
  • func (function): function to call

once

static 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 (string): Type of the event. See possible types of events below
  • func (function): function to call

off

static off(eventtype)

Stop listening to events of a certain type. Clears all events of the given type for this script entity.

Parameters

  • eventtype (string): Type of the event

emitExternal

static emitExternal(eventtype, value)

Parameters

  • eventtype
  • value

translate

static _translate(e)

Parameters

  • e

processIncoming

static _processIncoming(e)

Parameters

  • e

debugStats

static _debugStats()

Examples

For examples and more information, see Handling Events.