Talk:LlSleep

From Second Life Wiki
Revision as of 19:23, 13 January 2014 by LepreKhaun Resident (talk | contribs) (Use of small values with llSleep())
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Use of small values with llSleep()

I believe these 2 script shows that a small value (as in less than 0.0222... (1/45)) sent to llSleep() causes the script to sleep out the rest of the server frame it's then active within, always causing a minimal delay of approximately 0.022s. They also show that llSleep(0.0); is a NOP.

To show this, I'm using a technique to see what gets en-queued during the detach event. Both scripts announce when their attach event handler is triggered. The "Sub" script, when it detects a detach event message, also sends a link message to "Main" which then announces when it's been received. With either no llSleep() or with llSleep(0.0) in the indicated spot within "Sub", nothing is queued through the detachment. However, use of a small value will cause the response of the link message to delay until it's reattached again.

To use, place both scripts within one prim, attach and detach enough times to note the chat messages and when they occur. Uncomment either of the llSleep() statements in "Sub" to observe the differences. <lsl>// Main default{

   link_message(integer sender_num, integer num, string msg, key id){
       llOwnerSay(msg);
   }
   
   attach(key id){
       if (id == NULL_KEY)
           llOwnerSay("Main detached.");
       else 
           llOwnerSay("Main attached.");
   }

}</lsl>

<lsl>// Sub default{

   attach(key id){
   
       if (id == NULL_KEY){
           llOwnerSay("Sub detached.");
           

// Uncommenting next line will not change the observed behavior // llSleep(0.0);

// Uncommenting next line will cause this script to sleep until the end of the server frame // llSleep(0.0001);

           llMessageLinked(0, 0, "DETACHED", NULL_KEY);
       } else
           llOwnerSay("Sub attached.");
   }

}</lsl> LepreKhaun Resident 19:23, 13 January 2014 (PST)