grandMA3 User Manual Publication

Timer(string, integer, integer[, string[, handle]])

grandMA3 User Manual » Plugins » Lua Functions - Object-Free API » Timer(string, integer, integer[, string[, handle]])
Version 2.1

Description

The Timer Lua function call a different function using a timer. The other function can be called multiple times using the timer interval. 

Arguments

  • Function:
    This is the name of the function that is called multiple times using the timer.
  • Integer:
    This is the wait time between the calls. The value is in seconds.
  • Integer:
    This is the number of times the function is called.
  • Function | nil (optional):
    This is an optional argument that is the name of a function that is called when the Timer function is finished.
  • Handle (optional):
    This is an optional argument for a handle to an object that is passed to the called function.

Return

This function does not return anything.

Example

This example prints a greeting three times and then calls a clean up function:

Lua
-- Function that will be called several times.
function TimedFunction()
-- Check the value of RunAmount and print something.
if RunAmount < 1 then
Printf("Hello")
else
Printf("Hello again")
end
-- Add 1 to the RunAmount variable.
RunAmount = RunAmount + 1
end

-- Cleanup function.
function TimerCleanup()
Printf("Goodbye")
-- Delete the RunAmount variable.
RunAmount = nil
end

-- Function with the Timer call.
function Main()
-- Set a wait variable.
local waitSeconds = 1
-- Set a variable with the number of iterations.
local iterations = 3
-- Create a counter variable and set it to 0.
RunAmount = 0
-- Call the timer function.
Timer(TimedFunction, waitSeconds, iterations, TimerCleanup);
end

-- call the main function.
return Main