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

From Second Life Wiki
Jump to navigation Jump to search
m (added headline to show new/old versions more clearly)
m (Replaced old <LSL> block with <source lang="lsl2">)
Line 5: Line 5:




<lsl>integer on_off = FALSE; //STARTS IN THE OFF POSITION
<source lang="lsl2">integer on_off = FALSE; //STARTS IN THE OFF POSITION


default
default
Line 28: Line 28:
     }
     }
}
}
</lsl>
</source>


==Another way to do the same thing==
==Another way to do the same thing==


An "expert scripter" came along and changed this script nearly beyond recognition.  I have reverted their edits so that the version I use in class remains to match the student's notes.  However, the "expert" contribution may be useful to some people, so I am including their version here.
An "expert scripter" came along and changed this script nearly beyond recognition.  I have reverted their edits so that the version I use in class remains to match the student's notes.  However, the "expert" contribution may be useful to some people, so I am including their version here.
<lsl>
<source lang="lsl2">
integer on_off;// = FALSE;
integer on_off;// = FALSE;
   
   
Line 62: Line 62:
     }
     }
}
}
</lsl>
</source>
Notice that while it is similar... all the helpful notes were stripped off and the note which was left was now irrelevant to the way it was coded.  [[User:Toady Nakamura|Toady Nakamura]] 09:07, 4 November 2012 (PST)  P.S.  This is a user page, please do not make changes without using the "discussion" page, or merely appending your changes with explanation at the bottom.
Notice that while it is similar... all the helpful notes were stripped off and the note which was left was now irrelevant to the way it was coded.  [[User:Toady Nakamura|Toady Nakamura]] 09:07, 4 November 2012 (PST)  P.S.  This is a user page, please do not make changes without using the "discussion" page, or merely appending your changes with explanation at the bottom.

Revision as of 02:36, 22 January 2015

  • 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


integer on_off = FALSE; //STARTS IN THE OFF POSITION

default
{
    touch_start(integer total_number)
    {
        if (on_off == TRUE)        // if the light exactly equals "==" ON turn it off
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 0.5>, 1.0, 10.0, 0.75,PRIM_GLOW ,ALL_SIDES,0]);
            llOwnerSay("Light is Off");
            on_off = FALSE;     // Flip to FALSE now that light is OFF
                                // note here only one "=" sign as the value is being set
        
        }
        
        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]);
            llOwnerSay("Light is On");
            on_off = TRUE;  // flip to TRUE now that light is ON
        }
    }
}

Another way to do the same thing

An "expert scripter" came along and changed this script nearly beyond recognition. I have reverted their edits so that the version I use in class remains to match the student's notes. However, the "expert" contribution may be useful to some people, so I am including their version here.

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.");
        }
    }
}

Notice that while it is similar... all the helpful notes were stripped off and the note which was left was now irrelevant to the way it was coded. Toady Nakamura 09:07, 4 November 2012 (PST) P.S. This is a user page, please do not make changes without using the "discussion" page, or merely appending your changes with explanation at the bottom.