Skip to content

Timers & Intervals

Timers work in persistent scripts (started with lua:start). They fire on the main thread during the render frame.

local id = pl.set_interval(1000, function()
pl.log("Every second")
end)

Returns a timer ID. The callback fires every ms milliseconds.

local id = pl.set_timeout(5000, function()
pl.log("5 seconds later")
end)

Fires once after ms milliseconds, then auto-removes.

pl.clear_interval(id)
pl.clear_timeout(id) -- same function, works for both
pl.set_interval(300000, function() -- 5 minutes
pl.log("Reminder: save your project!")
end)
-- Start recording, then stop after 8 bars
pl.cmd("transport:toggle-record")
local transport = pl.get_transport()
local bar_duration_ms = (60000 / transport.tempo) * transport.timeSigNum * 8
pl.set_timeout(bar_duration_ms, function()
pl.cmd("transport:stop")
pl.log("Recording stopped after 8 bars")
end)
  • Timers are checked each render frame (~16ms at 60fps)
  • Timer resolution is frame-rate dependent, not sample-accurate
  • For sample-accurate timing, use pl.on_beat or pl.on_bar instead
  • One-shot timers are automatically cleaned up after firing