LSL light switch script: touch to turn a lamp on and off
Free LSL light script for Second Life lamps, candles and bulbs: touch to switch real light, glow and full bright on and off, with colour and radius settings.
Turn any lamp, bulb, candle or neon sign into a working light. Touch it and this light switch script turns on real Second Life light, a soft glow and full bright on the face you choose. Touch again to turn it all off.
// Light Switch - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-light-switch-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Put this script in a lamp, bulb or candle. Touch to turn the light on and off.
// The prim gives real light, and can glow and be full bright while it is on.
vector LIGHT_COLOR = <1.0, 0.9, 0.7>; // warm white
float LIGHT_INTENSITY = 1.0; // 0.0 to 1.0
float LIGHT_RADIUS = 10.0; // metres, up to 20.0
float LIGHT_FALLOFF = 0.75; // 0.0 to 2.0
float GLOW_AMOUNT = 0.1; // 0.0 = no glow
integer USE_FULLBRIGHT = TRUE;
integer LIGHT_FACE = ALL_SIDES; // the face that glows, or ALL_SIDES
integer START_ON = FALSE;
integer gOn = FALSE;
setLight(integer on)
{
float glow = 0.0;
if (on) glow = GLOW_AMOUNT;
llSetLinkPrimitiveParamsFast(LINK_THIS, [
PRIM_POINT_LIGHT, on, LIGHT_COLOR, LIGHT_INTENSITY, LIGHT_RADIUS, LIGHT_FALLOFF,
PRIM_FULLBRIGHT, LIGHT_FACE, on && USE_FULLBRIGHT,
PRIM_GLOW, LIGHT_FACE, glow
]);
gOn = on;
}
default
{
state_entry()
{
setLight(START_ON);
}
touch_start(integer total)
{
setLight(!gOn);
}
}
Free to use, change and put in your own creations, also ones you sell.
How to set it up
- Put the script in the lamp's shade or bulb prim and save.
- Touch the lamp to switch it on and off.
- Change the colour, intensity and radius to fit the room.
Settings
- LIGHT_COLOR: the colour of the light. <1.0, 0.9, 0.7> is warm white, <0.7, 0.8, 1.0> is cool white.
- LIGHT_INTENSITY, LIGHT_RADIUS, LIGHT_FALLOFF: how strong the light is, how far it reaches and how quickly it fades.
- GLOW_AMOUNT: a soft glow on the lit face; 0.0 turns glow off.
- USE_FULLBRIGHT: makes the lit face look bright even at night.
- LIGHT_FACE: the face that glows (for example only the bulb), or ALL_SIDES.
- START_ON: whether the light is on after the script starts.
Tips
- Visitors only see the light itself if they have local lights enabled in their graphics settings. The glow and full bright still show.
- Many lights close together can slow the viewer. Use a few strong lights rather than many small ones.
Frequently asked questions
Why can't I see the light on the walls?
Your viewer's graphics settings may limit local lights. Turn up the graphics quality or allow local lights, and check that LIGHT_RADIUS reaches the walls.
Can one switch control several lamps?
This script controls its own prim. To control several lamps, the switch can send a message to the lamps with llMessageLinked (linked) or llRegionSay (not linked), and each lamp listens for it.
Can I make it turn on at night by itself?
Yes. Check the sun position with llGetSunDirection in a timer and switch the light when the sun goes down.