mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Clone
5
Timer
Robert Beekman edited this page 2017-09-12 14:23:12 +02:00
The Timer module lets you execute pieces of script with a delay and optionally multiple times.
Overview
Functions
SetTimer
Creates and starts a timer using the given variables.
Syntax:
timer SetTimer(function function, int interval, int timesToExecute, [params])
Required arguments
- function: A LUA function to be called each time the timer ticks
- interval: The amount of time in milliseconds between each tick
- timesToExecute: The amount of times to run the function, use 0 for infinite
Optional arguments
Note: The arguments between [brackets] are optional and you can leave them out.
- params: Paramaters you wish to pass to the function the timer will call on each tick
Example:
-- Simple example without passing arguments
local helloAmount = 1
function timedHello()
print("Hello! " .. helloAmount)
helloAmount = helloAmount + 1
end
Timer.SetTimer(timedHello, 1000, 5)
-- Example with passing arguments
local printAmount = 1
function timedPrint(text)
print(text .. printAmount)
printAmount = printAmount + 1
end
Timer.SetTimer(timedPrint, 1000, 5, "Hello! ")
RemoveTimer
Removes an existing timer.
RemoveTimer(timer timer)
Required arguments
- timer: The timer to remove
Example:
local helloTimer
function timedHello()
print("Hello!")
-- Stop the timer after running once
Timer.RemoveTimer(helloTimer)
end
helloTimer = Timer.SetTimer(timedHello, 1000, 5)