Skip to content
lsl.devlsl.devLSL Dev

llGetTime

function
Function syntax
float llGetTime();
Returns
float
Energy
10

Returns a float representing the elapsed script time in seconds with subsecond precision (since the script started, was reset, or since the last call to llResetTime or llGetAndResetTime).

Returns a float that is script time in seconds with subsecond precision since the script started, was last reset, or call to either llResetTime or llGetAndResetTime.

How to use
float result = llGetTime();

Script time matches normal time, it is unaffected by time dilation. For example, if you call llResetTime on two objects in separate simulators at the same time, and later call llGetTime on both at the same time, their values will be equal regardless of differences in dilation.

  • Script time is the amount of real-world time that the script has been in a running state. It is unaffected by time dilation, but it does not count time while the script is suspended, the user is offline (when in an attachment), the object is in inventory rather than rezzed, etc.
  • Script time resets when…
  • Script reset (user or llResetScript or llResetOtherScript)
  • Call to either llResetTime or llGetAndResetTime
  • Due to (32 bit) floating point number limitations, the accuracy of this function is 1/64sec up to ~3 days, 1/32sec up to ~6 days, etc… doubling each time, e.g. it’s only 1 second at ~194 days. Use llResetTime or llGetAndResetTime whenever practical to maintain the accuracy you require:
Floating Point Precision Thesholds
PrecisionUp to SecondsHoursDays
0.016=2-6262144=21872.823.03
0.022=1/451 simulator frame
0.031=2-5524288=219145.636.06
0.063=2-41048576=220291.2712.13
0.125=2-32097152=221582.5424.27
0.250=2-24194304=2221165.0848.54
0.500=2-18388608=2232330.1697.09
1.000=2-016777216=2244660.33194.18
  • Note that this precision caveat does not apply to scripts written in SLua, only to LSL scripts. In SLua:
  • the timer precision is 64-bit, and will maintain 1/64sec precision for ~4.4million years.
  • llResetTime and llGetAndResetTime have been removed
Example 1
default {
state_entry()
{
llResetTime();
}
touch_start(integer num_touch)
{
float time = llGetTime(); //Instead getting, and then resetting the time, we could use llGetAndResetTime() to accomplish the same thing.
llResetTime();
llSay(0,(string)time + " seconds have elapsed since the last touch." );
}
}
Example 2
6 collapsed lines
// Distinguish between a single click and a double click
float gHoldTime;
default
{
touch_start(integer total_number)
{
float now = llGetTime();
if (now - gHoldTime < 0.3)
{
11 collapsed lines
llSay(PUBLIC_CHANNEL,"Double clicked");
// Trigger one sequence of actions
}
else
{
llSetTimerEvent(0.32);
}
gHoldTime = now;
}
timer()
{
llSetTimerEvent(0.0);
if (llGetTime()-gHoldTime > 0.3)
{
llSay(PUBLIC_CHANNEL,"Single clicked.");
// Trigger a different sequence of actions
}
}
}
Example 3
// To do time-dependant loops of whatever:
// for example move 2 meters within 5.0 seconds
float time = 5.0;
float i;
llResetTime();
do
{
i = llGetTime()/time;
// move2meters*i
}
while (llGetTime() < time);
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from LlGetTime, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.