Skip to content

EventQueue

Represents a queue that collects and manages events, providing methods to access the latest event, wait for the next event, or stop collection.

Fields

names: table Read-Only

The names of the events that this queue is collecting.

Methods

latest() event: any

Returns the newest event in this queue and discards all older events. If the queue is empty, nil is returned. Use this method when only the most recent event is relevant, such as in updates.

Example

local queue = Events.collect("ChatMessageEvent")
while true do
  local event = queue:latest()
  if event ~= nil then
    spell:execute("say %s", event.message)
  end
  sleep(5 * 20)
end

Returns

  • any — event The latest event or nil if the queue is empty.

next(timeout: number|nil) event: any

Returns the next event in the queue, blocking until an event is available or the specified timeout (in game ticks) is reached. If no timeout is provided, this method blocks indefinitely until an event is available.

Example

local queue = Events.collect("ChatEvent")
while true do
  local event = queue:next()
  spell:execute("say %s", event.message)
end

Parameters

Name Type Description
timeout number|nil Optional timeout in game ticks. If not provided, blocks indefinitely.

Returns

  • any — event The next event or nil if the timeout is reached.