Jump to content

LlSetTimerEvent

From OSgrid Wiki

Function: llSetTimerEvent(float sec );

Sets the timer event to be triggered every sec seconds. Passing 0.0 (or just 0) stops further timer events.

The timer persists over state changes, but gets removed when the script is reset.

Caveats

OpenSimulator Differences

• In OpenSimulator the timer period is hard limited to no smaller than 0.5 seconds.
• This can be changed by setting ScriptDelayFactor to a value less than 1.0 in the XEngine section of the ini file.

• In SL several sources suggest that timer periods of [0.04] or [0.02] are possible.
• But actual measurements show that time periods below 0.20 seconds are never achieved on SL.

Examples

<source lang="lsl">

default {

   state_entry()
   {
       llSetTimerEvent(300); // five minutes: 5*60--no need to make LSL do this simple calculation
   }
   timer()
   {
       llOwnerSay("timeout");

// llSetTimerEvent(0); (to stop the timer)

   }

} </source>


Calling llSetTimerEvent replaces any existing timer value, and resets the countdown. In other words, if you call llSetTimerEvent(n) every n-1 seconds, the timer() event will never fire.

To stop the timer, call llSetTimerEvent(0.0). It's good practice to do this in the state_exit() event of any state which uses a timer to avoid unintentionally having a timer running in the next state.

See Also
Events:
• timer – event called every sec seconds