Difference between revisions of "Timer"

From Second Life Wiki
Jump to navigation Jump to search
(Example)
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSL_Event|event_id=11|event_delay|event=timer|event_desc=Result of the {{LSLG|llSetTimerEvent}} library function call.
{{LSL_Event|event_id=11|event_delay|event=timer|event_desc=Repeats the code in the timer(). Result of the [[llSetTimerEvent]] library function call.
|constants
|constants
|spec
|spec
|caveats
|caveats=
|examples=<pre>
*The time between timer events can be longer than that specified with [[llSetTimerEvent]], this is caused by:
integer counter = 0;
** '''Time dilation''' -  See [[llGetRegionTimeDilation]] for more information;
** '''Default event delay''' - Only so many events can be triggered per second;
** '''Event Execution''' - If the execution of an event takes too long;
** '''llSleep()'''.
*Only one timer can be active at one time.
*The timer survives state changes, but does not survive resets.
|examples=
<source lang="lsl2">
float gap = 2.0;
float counter = 0.0;


default
default
Line 11: Line 20:
     {
     {
         // Activate the timer listener every 2 seconds
         // Activate the timer listener every 2 seconds
         llSetTimerEvent(2);
         llSetTimerEvent(gap);
     }
     }


     timer()
     timer()
     {
     {
         counter = counter + 2;  
         counter = counter + gap;  
         llSay(0, (string)counter+" seconds are passed");
         llSay(0, (string)counter+" seconds have passed");
     }
     }
}
}
</pre>
</source>
|helpers
|helpers
|also_header
|also_header
Line 31: Line 40:
|deprecated
|deprecated
|cat1=Script
|cat1=Script
|cat2
|cat2=Time
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 00:06, 22 January 2015

Description

Event: timer( ){ ; }

Repeats the code in the timer(). Result of the llSetTimerEvent library function call.


Caveats

  • The time between timer events can be longer than that specified with llSetTimerEvent, this is caused by:
    • Time dilation - See llGetRegionTimeDilation for more information;
    • Default event delay - Only so many events can be triggered per second;
    • Event Execution - If the execution of an event takes too long;
    • llSleep().
  • Only one timer can be active at one time.
  • The timer survives state changes, but does not survive resets.


Examples

float gap = 2.0;
float counter = 0.0;

default
{
    state_entry()
    {
        // Activate the timer listener every 2 seconds
        llSetTimerEvent(gap);
    }

    timer()
    {
        counter = counter + gap; 
        llSay(0, (string)counter+" seconds have passed");
    }
}

See Also

Functions

•  llSetTimerEvent

Deep Notes

Signature

event void timer(  );