Difference between revisions of "Lua:Class:Timer"

From Cheat Engine
Jump to navigation Jump to search
(Examples)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Timer Class''' (Inheritance Component->object)
+
[[Category:Lua]]
 +
Timer '''class''': ('''Inheritance''': ''[[Lua:Class:Component|Component]]''->''[[Lua:Class:Object|Object]]'')
  
The timer class is an non visual component that when active triggers an onTimer event every few milliseconds, based on the given interval
+
The timer class is an non visual component that when active triggers an onTimer event every tick. (base on Interval property)
  
 +
== Creation ==
 +
; [[Lua:createTimer|createTimer]](''owner'' OPTIONAL, ''enabled'' OPTIONAL)
 +
: Returns a newly created 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 instead of being the responsibility of the owner object)
  
'''createTimer'''(owner, enabled OPT)  
+
Tip: use [[Lua:getMainForm|getMainForm]] for the owner of any timer so that it is destroyed when the main form is destroyed (closed).
 +
createTimer(getMainForm())
  
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)
+
== Properties ==
Owner may be nil, but you will be responsible for destroying it
+
; Interval : integer
 +
: The number of milliseconds (1000 = 1 second) between ticks (executions).
  
 +
; Enabled : boolean
 +
: The enable state of the Timer.
  
'''timer_setInterval'''(timer, interval)  
+
; OnTimer : function(timer)
 +
: The function to call when the timer triggers (tick).
  
Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second)
+
== Methods ==
  
 +
; getInterval() : integer
 +
: Returns the speed on how often the timer will trigger. In milliseconds (1000 = 1 second).
  
'''timer_getEnabled'''(timer)
+
; setInterval(''interval'')
 +
: Sets the speed on how often the timer should trigger. In milliseconds (1000 = 1 second).
  
Returns true if the timer is enabled otherwise false
+
; getOnTimer() : function(''timer'')
 +
: Returns the 'OnTimer' event.
  
 +
; setOnTimer(''function(timer)'')
 +
: Sets the 'OnTimer' event.
  
'''timer_setEnabled'''(timer, boolean)
+
; getEnabled() : boolean
 +
: Returns the enable state of the Timer.
  
Lets you enable of disable the timer
+
; setEnabled(''state'')
 +
: Sets the enable state of the Timer.
  
 +
== Examples ==
 +
local timer = createTimer(getMainForm())
 +
timer.Interval = 100
 +
timer.OnTimer = function(timer)
 +
  -- code setting done state.
 +
  if DoneState == true then
 +
    timer.destroy()
 +
  end
 +
end
  
'''timer_onTimer'''(timer, function)
+
local function timer_tick(timer)
 +
  -- code setting done state.
 +
  if DoneState == true then
 +
    timer.destroy()
 +
  end
 +
end
 +
local someTimer = createTimer(MainForm, false)
 +
someTimer.Interval = 100
 +
someTimer.OnTimer = timer_tick
 +
someTimer.Enabled = true
  
  function (sender)
+
local function timer_tick(timer)
 +
  -- code setting done state.
 +
  if DoneState == true then
 +
    timer.destroy()
 +
  end
 +
end
 +
local someTimer = createTimer()
 +
someTimer.Interval = 100
 +
someTimer.OnTimer = timer_tick
  
Example 1:
 
  
  function repeat()
+
{{LuaSeeAlso}}
  print "hello world" 
 
  end
 
  
  local t = createTimer(nil)  -- it will create a Timer object and assign it to variable t.
+
=== Related Functions ===
  timer_onTimer(t, repeat)  -- The function repeat will be called every 3 seconds.
+
* [[Lua:createTimer|createTimer]]
  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.
+
=== Related Classes ===
 +
* [[Lua:Class:Component|Component]]

Latest revision as of 22:15, 25 July 2018

Timer class: (Inheritance: Component->Object)

The timer class is an non visual component that when active triggers an onTimer event every tick. (base on Interval property)

Creation[edit]

createTimer(owner OPTIONAL, enabled OPTIONAL)
Returns a newly created 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 instead of being the responsibility of the owner object)

Tip: use getMainForm for the owner of any timer so that it is destroyed when the main form is destroyed (closed).

createTimer(getMainForm())

Properties[edit]

Interval : integer
The number of milliseconds (1000 = 1 second) between ticks (executions).
Enabled : boolean
The enable state of the Timer.
OnTimer : function(timer)
The function to call when the timer triggers (tick).

Methods[edit]

getInterval() : integer
Returns the speed on how often the timer will trigger. In milliseconds (1000 = 1 second).
setInterval(interval)
Sets the speed on how often the timer should trigger. In milliseconds (1000 = 1 second).
getOnTimer() : function(timer)
Returns the 'OnTimer' event.
setOnTimer(function(timer))
Sets the 'OnTimer' event.
getEnabled() : boolean
Returns the enable state of the Timer.
setEnabled(state)
Sets the enable state of the Timer.

Examples[edit]

local timer = createTimer(getMainForm())
timer.Interval = 100
timer.OnTimer = function(timer)
  -- code setting done state.
  if DoneState == true then
    timer.destroy()
  end
end
local function timer_tick(timer)
  -- code setting done state.
  if DoneState == true then
    timer.destroy()
  end
end
local someTimer = createTimer(MainForm, false)
someTimer.Interval = 100
someTimer.OnTimer = timer_tick
someTimer.Enabled = true
local function timer_tick(timer)
  -- code setting done state.
  if DoneState == true then
    timer.destroy()
  end
end
local someTimer = createTimer()
someTimer.Interval = 100
someTimer.OnTimer = timer_tick


See also[edit]

Related Functions[edit]

Related Classes[edit]