Schedule tasks to be executed later.
local on_tick_n = require("__flib__.on-tick-n")
init() | Initialize the module's script data table. |
retrieve(tick) | Retrieve the tasks for the given tick. |
add(tick, task) | Add a task to execute on the given tick. |
remove(ident) | Remove a scheduled task. |
TaskIdent | A unique identifier for a previously added task, used in on-tick-n.remove. |
Tasks | An table of tasks. |
Initialize the module's script data table.
Must be called at the beginning of on_init
. Can also be used to delete all current tasks.
Retrieve the tasks for the given tick.
Must be called during on_tick
.
Add a task to execute on the given tick.
Parameters:
Remove a scheduled task.
Parameters:
A unique identifier for a previously added task, used in on-tick-n.remove.
An table of tasks.
Each task can be anything that is not a function, as specified in on-tick-n.add.
This is not an array, there may be gaps. Always use pairs
to iterate this table.
event.on_tick(function(e)
for _, task in pairs(on_tick_n.retrieve(e.tick) or {}) do
if task == "say_hi" then
game.print("Hello there!")
elseif task == "order_66" then
for _, player in pairs(game.players) do
player.die()
end
end
end
end)