Difference between revisions of "User:Toady Nakamura/Touch Toggle Light"

From Second Life Wiki
Jump to navigation Jump to search
m (minor)
m (some readability improvements)
Line 5: Line 5:




<lsl>integer on_off = FALSE; //STARTS IN THE OFF POSITION
<lsl>
integer on_off = FALSE;


default
default
{
{
     touch_start(integer total_number)
     touch_start(integer num_detected)
     {
     {
         if (on_off == TRUE)       // if the light exactly equals "==" ON turn it off
    //  toggle between TRUE (1) and FALSE (0)
        on_off = !on_off;
 
         if (on_off == TRUE)
         {
         {
             llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 0.5>, 1.0, 10.0, 0.75,PRIM_GLOW ,ALL_SIDES,0]);
             llSetLinkPrimitiveParamsFast(LINK_THIS,
             llOwnerSay("Light is Off");
                [PRIM_POINT_LIGHT, FALSE, <1.0, 1.0, 0.5>, 1.0, 10.0, 0.75,
            on_off = FALSE;    // Flip to FALSE now that light is OFF
                PRIM_GLOW, ALL_SIDES, (float)FALSE]);
                                // note here only one "=" sign as the value is being set
 
       
             llOwnerSay("Light has been turned off.");
 
         }
         }
       
         else
         else // otherwise do the opposite
         {
         {
             llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 0.5>, 1.0, 10.0, 0.75,PRIM_GLOW ,ALL_SIDES,0.2]);
             llSetLinkPrimitiveParamsFast(LINK_THIS,
             llOwnerSay("Light is On");
                [PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.5>, 1.0, 10.0, 0.75,
            on_off = TRUE;  // flip to TRUE now that light is ON
                PRIM_GLOW, ALL_SIDES, 0.2]);
 
             llOwnerSay("Light has been turned on.");
         }
         }
     }
     }
}
}
</lsl>
</lsl>

Revision as of 08:10, 13 October 2012

  • Based on Simon Kline's "Scripting from Scratch Class" in 2010
  • Modified by Toady Nakamura
  • Place in prim, touch to change from dark to light.
  • Example of on/off toggling


<lsl> integer on_off = FALSE;

default {

   touch_start(integer num_detected)
   {
   //  toggle between TRUE (1) and FALSE (0)
       on_off = !on_off;
       if (on_off == TRUE)
       {
           llSetLinkPrimitiveParamsFast(LINK_THIS,
               [PRIM_POINT_LIGHT, FALSE, <1.0, 1.0, 0.5>, 1.0, 10.0, 0.75,
               PRIM_GLOW, ALL_SIDES, (float)FALSE]);
           llOwnerSay("Light has been turned off.");
       }
       else
       {
           llSetLinkPrimitiveParamsFast(LINK_THIS,
               [PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.5>, 1.0, 10.0, 0.75,
               PRIM_GLOW, ALL_SIDES, 0.2]);
           llOwnerSay("Light has been turned on.");
       }
   }

} </lsl>