new

Top  Previous  Next

timer.new creates a new timer object.

Definition

timerObj = timer.new( timeout, callback )

Name

Type

Description

timerObj

Timer Object

The timer object.

timeout

number

Number of miliseconds till callback is called.

callback

function(Timer Object)

The function to call.

Example

local counter = 0

local timerObj = timer.new(500, function(t)

  counter = counter + 1

  if (counter>= 50) then

        t:deinit()

  end

  print("hello", counter)

end)

 

timerObj:start()

 

This prints "hello 1" through "hello 20" 500 milliseconds apart into the Lua console.

Related

Timer Object

Availability

Lua