The EventQueue class collects events when it is connected to the event source.
The EventQueue class is a subtype of the Object class and inherits all its properties and functions.
Here is an overview of the EventQueue properties:
Property | Type | read / write |
---|---|---|
names | table | r |
Here is an overview of the EventQueue functions:
Function | Parameters | Results |
---|---|---|
isEmpty | boolean | |
latest | Event | |
next | timeout | Event |
stop | nil |
Below you find short descriptions about each of the properties and some examples about how to use them in your spells.
These are the names of all events this queue is collecting.
Below you find short descriptions about each of the functions and some examples about how to use them in your spells.
The ‘isEmpty’ function returns true if this queue is empty, false otherwise.
Busy-waiting for a chat event and printing the message when it occurs.
local queue = Events.collect("ChatEvent")
while queue:isEmpty() do
sleep(20)
print("still waiting...")
end
local event = queue:next(0)
print("You said "..event.message)
The ‘latest’ function returns the newest event in this queue and discards all older events. If the queue is empty then nil is returned. This is useful for update events where you are only interested in the most recent change.
Echo the last chat message every 5 seconds.
local queue = Events.collect("ChatEvent")
while true do
local event = queue:latest()
if event ~= nil then
spell:execute("say %s", event.message)
end
sleep(5 * 20)
end
The ‘next’ function returns the next event in this queue, if any. This function blocks until an event is available or the given timeout (measured in game ticks) is reached. If no timeout is specified, this function blocks forever.
Echoing all chat messages.
local queue = Events.collect("ChatEvent")
while true do
local event = queue:next()
spell:execute("say %s", event.message)
end
The ‘stop’ function stops collecting events into this queue.
Collecting chat events and stopping it after the first event occurs.
local queue = Events.collect("ChatEvent")
local event = queue:next()
print(str(event))
queue:stop()