Difference between revisions of "Lua:Class:Timer"
Jump to navigation
Jump to search
(Penny) |
m (Reverted edits by 211.13.46.219 (Talk) to last revision by Dark Byte) |
||
Line 1: | Line 1: | ||
− | + | '''Timer Class''' (Inheritance Component->object) | |
+ | The timer class is an non visual component that when active triggers an onTimer event every few milliseconds, based on the given interval | ||
+ | |||
+ | |||
+ | '''createTimer'''(owner, enabled OPT) | ||
+ | Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned) | ||
+ | Owner may be nil, but you will be responsible for destroying it | ||
+ | |||
+ | |||
+ | '''timer_setInterval'''(timer, interval) | ||
+ | Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second) | ||
+ | |||
+ | |||
+ | '''timer_getEnabled'''(timer) | ||
+ | Returns true if the timer is enabled otherwise false | ||
+ | |||
+ | |||
+ | '''timer_setEnabled'''(timer, boolean) | ||
+ | Lets you enable of disable the timer | ||
+ | |||
+ | |||
+ | '''timer_onTimer'''(timer, function) | ||
+ | |||
+ | function (sender) | ||
+ | |||
+ | Example 1: | ||
+ | |||
+ | function rep() | ||
+ | print "hello world" | ||
+ | end | ||
+ | |||
+ | local t = createTimer(nil) -- it will create a Timer object and assign it to variable t. | ||
+ | timer_onTimer(t, rep) -- The function repeat will be called every 3 seconds. | ||
+ | timer_setInterval(t,3000) --Call repeat() every 3 seconds | ||
+ | timer_setEnabled(t, true) -- Set timer to true. If false is passed as argument then it will disable timer object. |
Revision as of 18:51, 15 May 2012
Timer Class (Inheritance Component->object)
The timer class is an non visual component that when active triggers an onTimer event every few milliseconds, based on the given interval
createTimer(owner, enabled OPT)
Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned) Owner may be nil, but you will be responsible for destroying it
timer_setInterval(timer, interval)
Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second)
timer_getEnabled(timer)
Returns true if the timer is enabled otherwise false
timer_setEnabled(timer, boolean)
Lets you enable of disable the timer
timer_onTimer(timer, function)
function (sender)
Example 1:
function rep() print "hello world" end local t = createTimer(nil) -- it will create a Timer object and assign it to variable t. timer_onTimer(t, rep) -- The function repeat will be called every 3 seconds. timer_setInterval(t,3000) --Call repeat() every 3 seconds timer_setEnabled(t, true) -- Set timer to true. If false is passed as argument then it will disable timer object.