User:Omei Qunhua/Example Scripts

From Second Life Wiki
< User:Omei Qunhua
Revision as of 09:59, 9 January 2013 by Omei Qunhua (talk | contribs) (Start a collection of useful scripts and snippets)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Compute a negative channel based on user id <lsl> // Global:- integer gChannel;

//state_entry etc. :-

   gChannel = 0x80000000 | (string) llGetOwner();

</lsl>

Compute a random integer

<lsl> // 16777216 is the largest positive integer that can be accurately represented in a float in LSL // Using llFrand with larger number will start producing even numbers only, then eventually numbers divisible by 4, then 8 ... etc.

integer iRand = (integer) llFrand(16777215); </lsl>

Detect a long mouse click+hold for accessing special functionality

<lsl> default {

   touch_start(integer num_detected)
   {

llResetTime();

   }
   touch(integer num_detected)
   {

if (llDetectedKey(0) == llGetOwner() && llGetTime() > 1.0) { // The owner has touched this object for longer than 1 second // execute some special feature such as issuing a management dialog // ... }

   }
   touch_end(integer num_detected)
   {

if (llGetTime() < 1.0) { // The user did a normal quick click on the object // execute actions for normal clicks // ... }

   }

} </lsl>