Lesson 5.6 – Creating a lighted lamp (ready code)

The task - creating a lamp

In this lesson we will learn to create a lamp that can be lit by clicking on it.

We will open the CREATE menu and build the shape of the lamp.

Open the CONTENT tab and click on the NEW SCRIPT button, then copy the prepared SCRIPT directly from the link.

Or, Click on The Copy button on the uppper right corner of the code you see here next:

				
					// 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()
    {
    }

    touch_start(integer num_detected)
    {
        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;
            }
    }
}

				
			

Paste the copied code by pressing CTRL + V, and press the SAVE button.

After the CREATE menu is closed, the light will turn on and off by clicking the lamp.