Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Bunch'a constants.
  2. string A_THING        = "thing";   // Name of a prim you expect to find in the linkset.
  3. string SOMETHING_ELSE = "another"; // Another one.
  4. string THIRD_THING    = "a third"; // And another.
  5.  
  6. vector WHITE = <1.0, 1.0, 1.0>; // Always remember to type the .0 where LSL expects a float.
  7. vector RED   = <1.0, 0.0, 0.0>; // Otherwise, the script has to do extra work.
  8.  
  9. // Note that if we were using the LSL preprocessor, constants can be done with #define instead.
  10. //
  11. //  [ Also note that unless these strings are four characters or less,
  12. //    it does waste some memory to do it this way.
  13. //    This is not a concern unless you're an LSL guru. ]
  14. //
  15. // Integer, float, and vector constants should all be done as #defines.
  16.  
  17. // Our global variables, very important.
  18. integer thing; integer something; integer third;
  19.  
  20. integer setup_linkset() {
  21.     llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_TEXT, "", WHITE, 0.0]);
  22.    
  23.     // Now we look for the prims we require.
  24.    
  25.     // Setting these to an invalid value so we can tell if we couldn't find something.
  26.     thing = -1; something = -1; third = -1;
  27.    
  28.     integer i; integer guard = llGetNumberOfPrims();
  29.     string name;
  30.     for(i = 1; i <= guard; ++i) {
  31.         // Prims in a linked object are numbered from 1 to the number of prims, inclusive.
  32.         name = llGetLinkName(i);
  33.         if      (name == A_THING)        { thing = i; }
  34.         else if (name == SOMETHING_ELSE) { something = i; }
  35.         else if (name == THIRD_THING)    { third = i; }
  36.     }
  37.    
  38.     if (something < 0) { // We've decided that we can't go on if we don't find this prim.
  39.         llSetText("Bootup failure.", RED, 1.0); // Report failure to the user...
  40.         return FALSE;                           // ... and to the rest of the script.
  41.     }
  42.    
  43.     return TRUE; // Report success.
  44. }
  45.  
  46. integer last_prims; // The number of prims we had last time we booted up.
  47.  
  48. // Make functions from code snippets you find yourself copy/pasting.
  49. prim_text(integer lnum, string text) {
  50.     llSetLinkPrimitiveParamsFast(thing, [PRIM_TEXT, text, WHITE, 1.0]);
  51. }
  52.  
  53. default { state_entry() {
  54.     last_prims = llGetNumberOfPrims();
  55.    
  56.     if (!setup_linkset()) { state idle; } // Try to setup, and go idle if we fail.
  57.    
  58.     state active;
  59. } }
  60.  
  61. // If we're here, we failed to find what we need.
  62. state idle { touch_end(integer n) { if (llDetectedKey(0) == llGetOwner()) {
  63.     state default; // Only change states on touch inside a touch_end... bad things will happen otherwise.
  64. } } }
  65.  
  66. // In a real script, this is where normal operation would happen.
  67. state active {
  68.     state_entry() { // Do something amazing!
  69.         prim_text(thing,     "a thing");
  70.         prim_text(something, "the something");
  71.         prim_text(third,     "third thing");
  72.     } // Okay, maybe not that amazing. But you get the idea.
  73.    
  74.     changed(integer change) { if (change & CHANGED_LINK) {
  75.         integer prims = llGetNumberOfPrims();
  76.         if (prims == last_prims) { return; } // No change, do nothing.
  77.         state default; // If we got here, it changed.  Reconfigure!
  78.     } }
  79.    
  80.     touch_start(integer n) {
  81.         integer lnum = llDetectedLinkNumber(0);
  82.         // The 0 means we're asking about the first touch, if there were a bunch at the same time.
  83.         // [ This is how all the llDetected* functions work. ]
  84.        
  85.         // Figure out what prim was touched, and do something appropriate.
  86.         if (lnum == thing) {
  87.             llSay(0, "get'cha handz off mah primz!");
  88.             llSleep(1.0);
  89.             llSay(0, "... sorry.");
  90.         } else if (lnum == something) {
  91.             llSay(0, "the all-important something!");
  92.         }
  93.         else if (lnum == third) { llOwnerSay("yo."); }
  94.         else                    { llOwnerSay("."); }
  95.     }
  96.    
  97.     // Something you could do instead.
  98.     //touch_end(integer n) { if (llDetectedKey(0) == llGetOwner()) { llResetScript(); } }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement