Timer_Cancel()
Syntax: _Timer_Cancel(TimerName)
Purpose: Stops and completely removes a timer you've previously created.
Parameters:
TimerName: The name or handle that was returned when you initially created the timer using Timer_Create.
Timer_Create()
Syntax: _Timer_Create(delay, function_to_execute, iterations, create_paused)
Purpose: Creates a new timer to execute code after a specified delay. Timers are powerful for scheduling actions or repeating tasks.
Parameters:
delay: The time interval in milliseconds before the timer triggers the first time.
function_to_execute: The function to call when the timer fires. This can be a function name or a table listener with a "timer" method.
iterations: (Optional) How many times the timer should fire. Use 0 or -1 for infinite repetition.
create_paused: (Optional) If true, the timer starts in a paused state. Default is false.
Returns: A timer handle (name) used for later pausing, resuming, or cancelling the timer.
Important Notes:
Timer Accuracy: Timers are not perfectly precise. Their execution depends on the framerate of your app.
Table Listener: If providing a table as a listener, it needs to have a method named "timer" to handle timer events.
Timer_Pause()
Syntax: _Timer_Pause(TimerName)
Purpose: Temporarily pauses a running timer.
Parameters:
TimerName: The name or handle of the timer to pause (obtained from Timer_Create).
Timer_Resume()
Syntax: _Timer_Resume(TimerName)
Purpose: Restarts a timer that was previously paused.
Parameters:
TimerName: The name or handle of the timer to resume (obtained from Timer_Create).
Example:
-- Create a timer to print "Hello" every half second
myTimer = _Timer_Create(
500
,
function
()
_Print_Console(
"Hello"
)
end
,
-1
)
-- -1 for infinite repetition
-- Later, after some other code...
_Timer_Pause(myTimer)
-- Pause the timer
-- Even later...
_Timer_Resume(myTimer)
-- Resume the timer
--Finally stop the timer completely
_Timer_Cancel(myTimer)