Lighting System - adrianomesl/script_shack_support GitHub Wiki

Lighting System is a set of scripts created to allow home owners to setup lamps controlled by wall switches.

Most lamps in Second Life are clickable, which is good but in real life we don't touch the ceiling lamp to turn it on, we use wall switches. This Lighting System is meant to do exactly that same thing.

The package includes one switch, one light bulb and a foldable ceiling lamp which uses a projector to provide directional light. These three objects are provided for demonstration purposes but they look decent enough to be used.

Setup

The minimum setup we can build is composed by one switch and one lamp. One switch can control any number of lamps. At the same time, one lamp can be controlled by more than one switch.

Controlling one lamp with multiple switches

When we set up one lamp to be controlled by more than one switch we have to specifically mark the lamp as having multiple switches: we are going to see this in detail in the Configuration section below, look for HasMultipleSwitches.

Switch configuration

[General]

ChannelSeed key - Default: 00000000-0000-0000-0000-000000000000

The seed is used to calculate the communication channel, therefore the switch and the lamps it controls must have the same seed.

FaceOff integer - Default: 1

The number of the face to show when the switch goes to off position.

FaceOn integer - Default: 2

The number of the face to show when the switch goes to on position.

Reach (10m|20m|100m|region) - Default: 10m (Since version 1.1.0)

The reach of a switch determines how far a lamp can be to react to it. In general, for script global efficiency shortest distances are better but, as always, there are specific cases that requires flexibility. Since version 1.1.0 the default distance went from 20 meters to 10 meters but the Reach settings was added to allow to extend the reach as far as the whole region if necessary.

[Sound]

On string/key - Default: click_sound

The sound to play when the switch goes to on position.

Off string/key - Default: click_sound

The sound to play when the switch goes to off position.

[Lamps]

Here we list the lamps that are to be controlled with this switch by name. Enter one name per line.

Lamp configuration

[General]

[General]

ChannelSeed key - Default: 00000000-0000-0000-0000-000000000000

The seed is used to calculate the communication channel, therefore the lamp and the switch that controls it must have the same seed.

Faces Comma separated list - DefaultL: 1

This is a list of all the faces of an object that need to be turned into lights. In the great majority of cases we only want to have one face as light source because whether we use projectors or not, we can't really control where light is coming out from. The only reason why we may want to set more than one face here is to take advantage of the fact that these faces will change color and glow... thus giving the illusion of light coming from them for aesthetic purposes only.

HasMultipleSwitches (no|yes) - Default: no

Any lamp can be controlled by multiple switches but there are two different possible behaviours for the lamp when more than one switch is controlling it:

  • Default behaviour. The default behaviour is in place if HasMultipleSwitches is missing or set to no. In this case, a lamp that is ON can only be turned OFF when a switch send the turn-off command. In the same way, a lamp can only be turned ON when it receives a turn-on command from any switch.

  • Has multiple switches. When HasMultipleSwitches is set to yes the lamp will behave more like a real life lamp controlled by multiple switches, that is: any switch will toggle the current state of the lamp regardless of the switch state and the lamp state.

[LightOn] and [LightOff]

The other two configuration sections correspond to the settings of the light and faces when the lamp is on and when the lamp is off. Both states have the exact same attributes so we will describe them once.

LampColorHex Hex - Default: ffffff

The color of the light and also of the face(s) listed above.

ProjectorTexture string/key - Default: none

By default ProjectorTexture is empty which means that the light will not use a projector; Instead it will be a normal light bulb. To use a projector we need to specify the UUID of a texture or the name of a texture that is inside the object's inventory along with the script.

The rest of the attributes are related one to one with LSL Light properties. I won't get into details here but I will enumerate them and provide you a link to the official Wiki with everything you need to know about them:

LightIntensity Float

LightRadius Float

LightFalloff Float

LightFov Float

LightFocus Float

LightAmbience Float

GlowIntensity Float

ColorAlpha Float

LSL Light - Second Life Wiki

Included resources

The package includes multiple objects to help you get started with Lighting System.

Light bulb

A simple mesh that looks like a light bulb. This object includes the lamp script and will work out-of-the box with the provided switch.

Directional light

A low poly foldable lamp. This object has two linked parts which allow you to fold and rotate the lamp to aim the light to any direction. This lamp includes the lamp script in projector mode. The projector texture used in this lamp is also included in the package: look for light_projector-circle_light-white_20blur - cmt.

Single button two-states switch

The provided switch object is a wall mounted switch with a two state button. The button can be in one of two possible states: on and off. The object is animated by using one face for the on position button and another face for the off position button. These faces are referenced in the Switch configuration section as FaceOn and FaceOff.

This switch has a all-in-one version of the script including: light control + sound control + switch state control. You can use this script in any object you own provided that the object has two alternate faces dedicated to the on and off positions.

If your custom switch does not work this way, don't worry: you are covered... please keep on reading.

Lighting System Test Set

The purpose of this object will be clear to you as soon as you rezz it. Here are some things to look at here:

  • Each switch controls two lamps.
  • The projector lights and the color of the light face are the same. Note that you must have advanced lighting mode enabled for this to work.
  • The light bulbs can also be colored.
  • Study the configuration files, change settings and see what happens. Don't be afraid to break it, you have a clean copy in your inventory.

The best way to create new light settings is to edit the light face and use the in-world feature light editor to find the values you want. Then, copy them to the configuration file under LightOn.

Custom Switch Demo

The custom switch demo included in the package is a prim cube. If you edit the cube and look its inventory you'll see the following files inside:

  • Sound file: click_sound
  • Script: switch-light
  • Script: switch-object cmt
  • Script: switch-sound cmt
  • Notecard: switch.ini

This demo doesn't do anything impressive, it actually looks like it's not working well because it just hides and shows a face of the cube; However this simple demo is the starting point for you to create any kind of switches with any behaviour you want to give them.

Script: switch-light

This version of the script is dedicated exclusively to controlling the light. All the other functionality present in the all-in-one version we discussed earlier is not available in this script.

This script must be present as-is in any custom switches you create along with the switch.ini configuration file.

Script: switch-object cmt

The purpose of this script is to give you a skeleton for you to implement the behaviour of any custom switch you create. As we discussed above under Single button two-states switch, the all-in-one script will work if the object has dedicated faces to show alternatively depending on the switch's state. If you create a switch that doesn't have any kind of animations or the animation consists in moving parts instead of hiding/showing faces then you have to write your behaviour yourself and put it your copy of switch-object cmt.

Script: switch-sound cmt

The purpose of this script is to give you a skeleton for you to implement the sound effects of any custom switch you create. If all you need is to play a sound when the button is touched, just edit the script and enter the name or UUID of the sounds in the following lines:

string SOUND_ON = "click_sound";
string SOUND_OFF = "click_sound";

As you see this script is ready to work for a simple scenario like this; but if you want a more elaborate sound effect, you can write your own code for whenSwitchOn() and whenSwitchOff() functions.