Difference between revisions of "GetTime"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 1: Line 1:
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
+
==getTime==
<span class="bold">Command History</span>
+
Returns the number of milli seconds since the command was called the first time (or the timer was reset). Use this command for relative time measurements. E.g. call this command twice at different locations and calculate the time differential to see the time passed.
<div class="mw-collapsible-content">
+
<div class="command-min-version-info">Available since: <span class="command-min-version">v3.0</span></div>
<div class="alt-bg">Available since v3.7</div>
 
</div></div>
 
  
 +
Lua Syntax:
 +
<pre class="command-syntax">getTime({flags=1,
 +
    reset = true|false})</pre>
 +
===Arguments===
 +
===Flags===
 +
====r/reset====
  
Returns the number of milliseconds since the command was first called - or since the timer was reset! <br/>
+
:If true the timer will be reset and the next call(s) will return the time passed since this call.
Use this command for relative time measurements; for example: call getTime() at the beginning of an action & then again when the action has finished to get the time taken to perform said action!
+
===Return Values===
 
+
;time
 
+
:Milli seconds
Syntax:
+
===Examples===
 +
Example 1:  
 
<syntaxhighlight>
 
<syntaxhighlight>
getTime({flags=1, reset})
+
-- we'll use this function to check current time elapsed & decide what action to perform
</syntaxhighlight>
 
 
 
 
 
Example:
 
<syntaxhighlight>
 
-- let's store the current time in a variable & then check it against current time!
 
local initialTime = getTime()
 
 
 
-- we'll use this function to check current time elapsed & decided what action to perform!
 
 
function checkTime()
 
function checkTime()
if getTime() >= initialTime + 3000 then -- if current time more than equals initial time + 3 seconds then ...  
+
  if getTime() > 3000 then -- if time elapsed is more than 3 seconds then ...
  -- do some action!
+
    -- do some action
  getTime({flags=1, reset=true}) -- let's reset timer back to zero!
+
    getTime({flags=1, reset=true}) -- let's reset timer back to zero
end
+
  end
 
end
 
end
  
-- the checkTime() function would be most effective, if included in a mainLoop event handler!
+
-- the checkTime() function would be most effective if included in a mainLoop event handler
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
 
<span class="bold underline">Arguments</span>
 
 
none
 
 
 
<span class="bold underline">Flags</span>
 
 
<span class="bold">r/reset</span> <br/>
 
True resets timer back to zero; false does nothing (if no flags are set then reset will be false by default)
 
 
 
<span class="bold underline">Return</span>
 
 
<span class="bold">time</span> <br/>
 
The integer value of the current time (in ms)
 
{{i18n|GetTime}}
 

Revision as of 17:11, 22 November 2013

getTime

Returns the number of milli seconds since the command was called the first time (or the timer was reset). Use this command for relative time measurements. E.g. call this command twice at different locations and calculate the time differential to see the time passed.

Available since: v3.0

Lua Syntax:

getTime({flags=1, 
    reset = true|false})

Arguments

Flags

r/reset

If true the timer will be reset and the next call(s) will return the time passed since this call.

Return Values

time
Milli seconds

Examples

Example 1:

-- we'll use this function to check current time elapsed & decide what action to perform
function checkTime()
  if getTime() > 3000 then -- if time elapsed is more than 3 seconds then ...
    -- do some action
    getTime({flags=1, reset=true}) -- let's reset timer back to zero
  end
end

-- the checkTime() function would be most effective if included in a mainLoop event handler