lesson 5.7 – creating a lamp breaker (ready code)
Task: Create a circuit breaker for the lamp of the previous lesson
In this lesson we will learn to create a switch which will control the function of the lamp.
First build the new lamp in a specific area of the house.
In the CONTENT tab we will create a new SCRIPT and copy the SCRIPT for the lamp
Then, save the changes by the SAVE button.
To receive and copy the code, click on the
Or, Click on The Copy button on the uppper right corner of the code you see here next:
// Code For The Lamp
// Global variable declarations
integer gLightOn = 0;
// All LSL programs must have a default state
default
{
// All states should have a state_entry event
state_entry()
{
// put llListen statements in state_entry
llListen(-1986, "Button", NULL_KEY, "Light");
}
listen(integer m_channel, string m_name, key m_id, string m_message)
{
if ((gLightOn))
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1.0,1.0,1.0>, 1.0, 10.0, 0.01]);
llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, (float) 0]);
gLightOn = FALSE;
}
else
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0,1.0,1.0>, 1.0, 10.0, 0.01]);
llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, (float) 0.3]);
gLightOn = TRUE;
}
}
}
Now build the button that will control the lamp.
Build a cube and place it on the wall and change the name of the object to Button
(as shown earlier, in the code we defined that the object that will activate the lamp is called Button)
We will now create the code SCRIPT for itself.
Copy the
and paste it on a new SCRIPT you created for it.
Save the changes by clicking the SAVE button
Or, Click on The Copy button on the uppper right corner of the code you see here next:
// Code For The Breaker (SHALTER)
// Global variable declarations
// All LSL programs must have a default state
default
{
// All states should have a state_entry event
state_entry()
{
}
touch_start(integer num_detected)
{
llSay(-1986, "Light");
}
You can turn on the lamp by pressing the switch.