Difference between revisions of "timer.start"

From Inspired-Lua Wiki
Jump to navigation Jump to search
m (Text replace - "| <u>" to "| <u><center>")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
timer.'''start''' is a function that is part of the [[:Category:timer|timer]] functions.
 
timer.'''start''' is a function that is part of the [[:Category:timer|timer]] functions.
  
Starts the timer with the given period in seconds.<br />
+
This fucntion starts the timer with the given period in seconds.<br />
 +
This means that the this function fires the [[on.timer]]() event (that you have to define with a function in your code) will be called every x seconds, according to the period given in the parameter.<br />
 
If the timer is already running when this routine is called, the timer is reset to the new period.
 
If the timer is already running when this routine is called, the timer is reset to the new period.
  
This function fires the [[on.timer]]() event.
 
  
 
<br />
 
<br />
Line 17: Line 17:
 
! Parameter !! Type !! Description
 
! Parameter !! Type !! Description
 
|-
 
|-
| <u><center>period</u> || number || the time period for the timer to start. Must be > 0.05
+
| <u><center>period</center></u> || number || the time period in seconds for the timer to start. Must be > 0.01
 
|-
 
|-
 
|}
 
|}
  
 
== Example ==
 
== Example ==
<source>timer.start(0.5)</source>
+
 
 +
This example will display on the top-left corner of the screen a number going from 0 to infinity (it never stops), by adding 1 to ''variable'' every 0.5 seconds.
 +
 
 +
<source>
 +
variable = 0
 +
 
 +
function on.timer()
 +
  timer.stop()  -- stops the current timer. Not necessary.
 +
  variable = variable + 1
 +
  platform.window:invalidate()  -- screen refresh (on.paint is called)
 +
end
 +
 
 +
function on.paint(gc)
 +
  timer.start(0.5) -- will fire the on.timer event every half second.
 +
  gc:drawString(variable,0,0,"top")  -- display the number
 +
end</source>
  
 
== See also ==
 
== See also ==

Latest revision as of 18:45, 7 January 2012

timer.start is a function that is part of the timer functions.

This fucntion starts the timer with the given period in seconds.
This means that the this function fires the on.timer() event (that you have to define with a function in your code) will be called every x seconds, according to the period given in the parameter.
If the timer is already running when this routine is called, the timer is reset to the new period.



This has been introduced in TI-Nspire OS 3.0 (Changes).


Syntax

timer.start(period)

Parameter Type Description
period
number the time period in seconds for the timer to start. Must be > 0.01

Example

This example will display on the top-left corner of the screen a number going from 0 to infinity (it never stops), by adding 1 to variable every 0.5 seconds.

variable = 0

function on.timer()
   timer.stop()  -- stops the current timer. Not necessary.
   variable = variable + 1
   platform.window:invalidate()  -- screen refresh (on.paint is called)
end

function on.paint(gc)
   timer.start(0.5)  -- will fire the on.timer event every half second.
   gc:drawString(variable,0,0,"top")  -- display the number
end

See also