Difference between revisions of "timer.getMilliSecCounter"

From Inspired-Lua Wiki
Jump to navigation Jump to search
(Created page with "timer.'''getMilliSecCounter''' is a function that is part of the timer functions. Returns the amount of milliseconds elapsed since last calculator reboot. In...")
 
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
timer.'''getMilliSecCounter''' is a function that is part of the [[:Category:timer|timer]] functions.
 
timer.'''getMilliSecCounter''' is a function that is part of the [[:Category:timer|timer]] functions.
  
Returns the amount of milliseconds elapsed since last calculator reboot.
+
Returns the amount of milliseconds elapsed since last calculator reboot.<br />
 
In the Computer software emulator, it returns an absolute negative time.
 
In the Computer software emulator, it returns an absolute negative time.
 +
<br />
  
 
The counter rolls over to zero when it passes 2<sup>32</sup> milliseconds.  
 
The counter rolls over to zero when it passes 2<sup>32</sup> milliseconds.  
 +
<br /><br />
  
 
{{Since|3.0}}
 
{{Since|3.0}}
  
 
== Syntax  ==
 
== Syntax  ==
timer.'''getMilliSecCounter'''()
+
timer.'''getMilliSecCounter'''()<br />
 
(No arguments)
 
(No arguments)
  
 
== Example  ==
 
== Example  ==
 
<syntaxhighlight>theTime = timer.getMilliSecCounter()</syntaxhighlight>
 
<syntaxhighlight>theTime = timer.getMilliSecCounter()</syntaxhighlight>
 +
 +
== Good to know ==
 +
In order to define a relative time origin, whether it's on calc or  in the emulator, this can be an example :
 +
 +
<source>function now()
 +
  local now = timer.getMilliSecCounter()
 +
    if now < 0 then
 +
      now = now + 2^31
 +
    end
 +
  return now
 +
end</source>
 +
 +
 +
If you want to do something after ''60'' seconds, for example, here is what you have to do :
 +
 +
<source>timeleft = 60-math.floor((math.abs(timer.getMilliSecCounter()) - math.abs(startTime))*0.001)
 +
-- startTime would be a variable defined earlier as '0', for instance.
 +
if math.abs(math.floor(timeleft)) == 0 then
 +
-- your code here --
 +
end</source>
  
 
== See also  ==
 
== See also  ==

Latest revision as of 12:21, 25 May 2011

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

Returns the amount of milliseconds elapsed since last calculator reboot.
In the Computer software emulator, it returns an absolute negative time.

The counter rolls over to zero when it passes 232 milliseconds.

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


Syntax

timer.getMilliSecCounter()
(No arguments)

Example

theTime = timer.getMilliSecCounter()

Good to know

In order to define a relative time origin, whether it's on calc or in the emulator, this can be an example :

function now()
  local now = timer.getMilliSecCounter()
    if now < 0 then
      now = now + 2^31
    end
  return now
end


If you want to do something after 60 seconds, for example, here is what you have to do :

timeleft = 60-math.floor((math.abs(timer.getMilliSecCounter()) - math.abs(startTime))*0.001)
-- startTime would be a variable defined earlier as '0', for instance.
if math.abs(math.floor(timeleft)) == 0 then
 -- your code here --
end

See also