1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-02 02:33:32 +00:00

Updated Timer (markdown)

Robert Beekman 2017-09-12 14:23:12 +02:00
parent 61ae8930d0
commit b019eaf301

@ -9,7 +9,7 @@ The Timer module lets you execute pieces of script with a delay and optionally m
Creates and starts a timer using the given variables. Creates and starts a timer using the given variables.
#### Syntax: #### Syntax:
```lua ```lua
timer SetTimer(function function, int interval, int timesToExecute, [params]); timer SetTimer(function function, int interval, int timesToExecute, [params])
``` ```
##### Required arguments ##### Required arguments
- **function:** A LUA function to be called each time the timer ticks - **function:** A LUA function to be called each time the timer ticks
@ -23,38 +23,38 @@ timer SetTimer(function function, int interval, int timesToExecute, [params]);
#### Example: #### Example:
```lua ```lua
-- Simple example without passing arguments -- Simple example without passing arguments
local helloAmount = 1; local helloAmount = 1
function timedHello() function timedHello()
print("Hello! " .. helloAmount); print("Hello! " .. helloAmount)
helloAmount = helloAmount + 1; helloAmount = helloAmount + 1
end end
Timer.SetTimer(timedHello, 1000, 5); Timer.SetTimer(timedHello, 1000, 5)
-- Example with passing arguments -- Example with passing arguments
local printAmount = 1; local printAmount = 1
function timedPrint(text) function timedPrint(text)
print(text .. printAmount); print(text .. printAmount)
printAmount = printAmount + 1; printAmount = printAmount + 1
end end
Timer.SetTimer(timedPrint, 1000, 5, "Hello! "); Timer.SetTimer(timedPrint, 1000, 5, "Hello! ")
``` ```
--- ---
### RemoveTimer ### RemoveTimer
Removes an existing timer. Removes an existing timer.
```lua ```lua
RemoveTimer(timer timer); RemoveTimer(timer timer)
``` ```
##### Required arguments ##### Required arguments
- **timer:** The timer to remove - **timer:** The timer to remove
#### Example: #### Example:
```lua ```lua
local helloTimer; local helloTimer
function timedHello() function timedHello()
print("Hello!"); print("Hello!")
-- Stop the timer after running once -- Stop the timer after running once
Timer.RemoveTimer(helloTimer); Timer.RemoveTimer(helloTimer)
end end
helloTimer = Timer.SetTimer(timedHello, 1000, 5); helloTimer = Timer.SetTimer(timedHello, 1000, 5)
``` ```
--- ---