llGetTime
float llGetTime()Returns the time in seconds since the last region reset, script reset, or call to either llResetTime or llGetAndResetTime.
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,
llResetScript(), orllResetOtherScript()) - Call to either
llResetTime()orllGetAndResetTime()
Floating Point Precision
Section titled “Floating Point Precision”Due to 32-bit floating point number limitations, the accuracy of this function decreases as the script runtime increases. The precision doubles approximately every 3 days of script runtime:
- 0.016 seconds (2^-6): accurate up to ~3 days
- 0.031 seconds (2^-5): accurate up to ~6 days
- 0.063 seconds (2^-4): accurate up to ~12 days
- 0.125 seconds (2^-3): accurate up to ~24 days
- 0.250 seconds (2^-2): accurate up to ~48 days
- 0.500 seconds (2^-1): accurate up to ~97 days
- 1.000 seconds (2^0): accurate up to ~194 days
Use llResetTime() or llGetAndResetTime() whenever practical to maintain the accuracy you require.
Examples
Section titled “Examples”Measuring Elapsed Time Between Events
Section titled “Measuring Elapsed Time Between Events”default { state_entry() { llResetTime(); } touch_start(integer num_touch) { float time = llGetTime(); llResetTime(); llSay(0, (string)time + " seconds have elapsed since the last touch."); }}Note: You could also use llGetAndResetTime() to accomplish the same thing with a single function call.
Detecting Single vs Double Clicks
Section titled “Detecting Single vs Double Clicks”float gHoldTime;
default{ touch_start(integer total_number) { float now = llGetTime(); if (now - gHoldTime < 0.3) { 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 } }}Time-Dependent Movement
Section titled “Time-Dependent Movement”// Move 2 meters within 5.0 secondsfloat time = 5.0;float i;llResetTime();do{ i = llGetTime() / time; // move 2 meters * i}while (llGetTime() < time);See Also
Section titled “See Also”llResetTime()- Reset the script time counterllGetAndResetTime()- Get the time and reset in one callllGetRegionTimeDilation()- Get the region’s time dilation factor