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¶
empty: boolean — Read-Only¶
Returns true if the queue contains no events.
names: string[ ] — 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 = spell:collect("ChatMessageEvent")
while true do
local event = queue:latest()
if event ~= nil then
spell:execute("say " .. event.message)
end
sleep(5 * 20)
end
Returns
- event: any — The latest event or
nilif the queue is empty.
next(timeout?: number) → 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 = spell:collect("ChatMessageEvent")
while true do
local event = queue:next()
spell:execute("say " .. event.message)
end
Parameters
- timeout?: number — Timeout in game ticks. If omitted, blocks indefinitely.
Returns
- event: any — The next event or
nilif the timeout is reached.
stop()¶
Stops the queue from collecting events, preventing further additions to it.
Example