Jump to content

Scripting Tutorial-05

From OSgrid Wiki
Revision as of 17:37, 17 August 2018 by Osgridadmin (talk | contribs) (Created page with "<source lang="lsl"> →Fu's basic light switch v0.1 - basic on/off toggle: integer DEBUG = TRUE; integer LINK_LAMP = 3; // named like this to match LSL's...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<source lang="lsl"> /*

 Fu's basic light switch
   v0.1
   - basic on/off toggle
  • /


integer DEBUG = TRUE;

integer LINK_LAMP = 3; // named like this to match LSL's LINK_ROOT constant used below


default {

   state_entry() {
       state unlit;
   }

}


state unlit {

   state_entry() {
       if(DEBUG){ llOwnerSay("state: unlit"); }
       llSetLinkPrimitiveParamsFast(LINK_ROOT, 
           [ PRIM_FULLBRIGHT, ALL_SIDES, FALSE ]
       );
       llSetLinkPrimitiveParamsFast(LINK_LAMP, 
           // the UUID here is the OSgrid specific one for 'Blank Texture'
           [ PRIM_FULLBRIGHT,  ALL_SIDES, FALSE,
             PRIM_TEXTURE,     ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f", <1,1,0>, <0,0,0>, 0 ]
       );
   }
   touch_end(integer num_touches) {
       if(llDetectedLinkNumber(0) == LINK_ROOT) {
           state lit;
       }
   }

}


state lit {

   state_entry() {
       if(DEBUG){ llOwnerSay("state: lit"); }
       llSetLinkPrimitiveParamsFast(LINK_ROOT, 
       
           [ PRIM_FULLBRIGHT, ALL_SIDES, TRUE ]
       );
       llSetLinkPrimitiveParamsFast(LINK_LAMP, 
           // like in the 'unlit' state, the UUID here is the OSgrid specific one for 'Blank Texture'
           [ PRIM_FULLBRIGHT,  ALL_SIDES, TRUE,
             PRIM_TEXTURE,     ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f", <1,1,0>, <0,0,0>, 0 ]
       );
   }
   touch_end(integer num_touches) {
       
       if(llDetectedLinkNumber(0) == LINK_ROOT) {
           state unlit;
       }
   }

} </source>