Second Life today in one place Gifts & freebies updated every hour 7 languages Free to list your store
12:49 SLT List your event+ List
Grid issue
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
LSL script

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.

41 lines ·

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.

lsl-light-switch-script.lsl · 41 lines Check this script
// 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

  1. Put the script in the lamp's shade or bulb prim and save.
  2. Touch the lamp to switch it on and off.
  3. 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.

Check your own script: LSL syntax checker →

More scriptsAll scripts
LSL script · 55 lines

LSL door script: touch to open, closes by itself

Free LSL door script for Second Life. Touch to open and close, the door swings on its hinge and closes by itself after a few seconds. Sounds optional.

LSL script · 69 lines

LSL sit and pose script for chairs and pose balls

Free LSL sit script for Second Life chairs, benches and pose balls: sit and play your own animation, set the sit position, hide the ball while in use.

LSL script · 96 lines

LSL tip jar script with thank-you message and total

Free LSL tip jar script for Second Life clubs, DJs, hosts and stores: quick pay buttons, a thank-you message, the total and last tipper in floating text.