Wait and repeat
function onSpawn(self) self:afterSeconds(3, function() self:destroy() end) self.pisca = self:every(30, function() self.visible = not self.visible end)endTimerId pisca_;
void onSpawn() override { afterSeconds(3, [this] { destroy(); }); pisca_ = every(30, [this] { visible = !visible; });}afterandeverycount in steps (60 per second);afterSeconds, in seconds.- Each function returns an id;
cancel(id)cancels it. - Timers end when the instance is destroyed.
Sequence with waits (Lua)
Section titled “Sequence with waits (Lua)”For an ordered series of events (enemy waves, a cutscene), self:run avoids counters in onUpdate. In C++, chain after calls.
self:run(function() wait(2) spawn("Enemy", 160, 0, "Instancias") waitUntil(function() return not any("Enemy") end) goTo("Vitoria")end)afterSeconds(2, [this] { spawn<Enemy>(160, 0, "Instancias"); espera_ = every(1, [this] { if (any<Enemy>()) return; cancel(espera_); goTo("Vitoria"); });});Reference: Timers.
