Difference between revisions of "Lua:Class:Timer"

From Cheat Engine
Jump to navigation Jump to search
Line 1: Line 1:
'''Timer Class''' (Inheritance Component->object)
+
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
 
  
 +
The timer class is an non visual component that when active triggers an onTimer event every tick. (base on Interval property)
  
'''createTimer'''(owner, enabled OPT)  
+
== Creation ==
  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)
+
; [[createTimer]](''owner'' OPTIONAL, ''enabled'' OPTIONAL)
  Owner may be nil, but you will be responsible for destroying it
+
: 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())
  
'''setInterval'''(interval)
+
== Properties ==
  Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second)
+
; Interval : integer
 +
: The number of milliseconds (1000 = 1 second) between ticks (executions).
  
 +
; Enabled : boolean
 +
: The enable state of the Timer.
  
'''getEnabled'''()
+
; OnTimer : function(timer)
  Returns true if the timer is enabled otherwise false
+
: The function to call when the timer triggers (tick).
  
 +
== Methods ==
  
'''setEnabled'''(boolean)
+
; getInterval() : integer
  Lets you enable of disable the timer
+
: 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).
  
'''onTimer'''(function)
+
; getOnTimer() : function(''timer'')
 +
: Returns the 'OnTimer' event.
  
  function (sender)
+
; setOnTimer(''function(timer)'')
 +
: Sets the 'OnTimer' event.
  
Example 1:
+
; getEnabled() : boolean
 +
: Returns the enable state of the Timer.
  
  function rep()
+
; setEnabled(''state'')
    print "hello world" 
+
: Sets the enable state of the Timer.
  end
 
 
 
  local t = createTimer(nil)  -- it will create a Timer object and assign it to variable t.
 
  t.onTimer=rep  -- The function repeat will be called every 3 seconds.
 
  t.Interval=3000 --Call repeat() every 3 seconds
 
  t.Enabled=true -- Set timer to true. If false is passed as argument then it will disable timer object.
 
  
 +
== See also ==
 +
* [[Lua]]
 +
* [[Help_File:Script engine|Script engine]]
  
----
+
=== Related Functions ===
 +
* [[createTimer]]
  
* [[Lua|Lua Functions and Classes]]
+
=== Related Classes ===
 +
* [[Component]]

Revision as of 04:58, 11 March 2017

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

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

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

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.

See also

Related Functions

Related Classes