Step
A small timer module that makes it easier to have action execute with an interval or after a delay.
Install / Use
/learn @Sheepolution/StepREADME
step
A small immediate mode timer module that makes it easier to have an action execute with a certain interval or after a delay.
Installation
The step.lua file should be dropped into an existing project and required by it.
step = require "step"
You can then use step to create a new timer.
Usage
Every
You create a new timer with step.new(time) or step.every(time). When updated, the timer will return true with time as the interval.
timer = step.every(3)
Update
Update the timer with timer:update(dt) or by calling your timer (timer(dt)) and pass the delta time as argument.
if timer:update(dt) then
print("This will be printed every 3 seconds.")
end
After
If you create a new timer with step.after() the timer will return true every frame after the timer reaches its set time.
timer = step.after(3)
if timer:update(dt) then
print("After 3 seconds this will be printed every frame.")
end
Once
If you create a new timer with step.once() the timer will return true on the frame the timer reaches its set time. After that it will return false and the timer needs to be manually reset.
timer = step.once(3)
if timer:update(dt) then
print("After 3 seconds this will be printed once.")
end
During
If you create a new timer with step.during() the timer will return true on every frame that the timer has not reached its set time. After that it will return false and the timer needs to be manually reset.
timer = step.during(3)
if timer:update(dt) then
print("This will be printed every frame until 3 seconds have passed")
end
Reset
You can always reset your timer with timer:reset() or simply calling your timer without arguments.
timer:reset()
timer()
Random
If you pass two numbers timer.new(lowest, highest) it will have a random length (with decimals) between those numbers after each reset.
timer = step.new(3, 5)
Set
You can use timer:set(t, [noreset]) to change the time for this timer. If noreset is true, the timer will not be reset.
timer = step.new(5)
timer:set(3)
Finish
You can use timer:finish() to set the timer to the end, meaning that on the next update with step.every it will return true and reset the timer.
timer = step.new(4.7)
timer:finish()
if timer(dt) then
print("On the first frame this will be printed and then again after 4.7 seconds.")
end
You can use timer:finish() to set the timer to the end, meaning that on the next update with step.every it will return true and reset the timer.
timer = step.new(4.7)
timer:finish()
if timer(dt) then
print("On the first frame this will be printed and then again after 4.7 seconds.")
end
By passing true for the parameter truly, the timer will have actually ended, meaning that on the next update with step.once it will return false.
timer = step.once(4.7)
timer:finish(true)
if timer(dt) then
print("This will never be printed")
end
License
This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.
Related Skills
node-connect
348.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
