Difference between revisions of "User:Toady Nakamura/Two States Light"

From Second Life Wiki
Jump to navigation Jump to search
m (some minor improvements)
(added LSL Tip)
Line 3: Line 3:
*Original framework 04-16-08 by [[User:Toady Nakamura|Toady Nakamura]]
*Original framework 04-16-08 by [[User:Toady Nakamura|Toady Nakamura]]
*Light call modified from Simon Kline's classes "Scripting from Scratch"  
*Light call modified from Simon Kline's classes "Scripting from Scratch"  
{{LSL Tip|This is a very basic example script for the Linden Scripting Language. Please do take note that when you rely on high performance scripts you're not advised to write a script that has more than one state, which is the default state. Rather use an integer to switch modes. A pleasant side effect is, you'll have more free memory.}}


<lsl>
<lsl>

Revision as of 08:06, 17 October 2012

Using two states can sometimes be an elegant solution to on/off.

  • Original framework 04-16-08 by Toady Nakamura
  • Light call modified from Simon Kline's classes "Scripting from Scratch"
KBcaution.png Important: This is a very basic example script for the Linden Scripting Language. Please do take note that when you rely on high performance scripts you're not advised to write a script that has more than one state, which is the default state. Rather use an integer to switch modes. A pleasant side effect is, you'll have more free memory.

<lsl> vector color = <1.0, 1.0, 1.0>; float intensity = 1.000;// from 0.0 up to 1.0 float radius = 10.000;// from 0.0 up to 20.0 float falloff = 0.750;// from 0.0 up to 2.0

default {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   touch_start(integer num_detected)
   {
       llSetLinkPrimitiveParamsFast(LINK_THIS,
           [PRIM_POINT_LIGHT, TRUE, color, intensity, radius, falloff,
           PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);
       state lightOn;
   }

}

state lightOn {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   touch_start(integer num_detected)
   {
       llSetLinkPrimitiveParamsFast(LINK_THIS,
           [PRIM_POINT_LIGHT, FALSE, color, intensity, radius, falloff,
           PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);
       state default;
   }

} </lsl>