Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

linking lighting switches?

Lyekahgood Nighbor
Registered User
Join date: 10 Aug 2006
Posts: 27
12-14-2006 00:46
hello wizards.

issue: built a three light lamp (3 bulbs) after I link it all together only 1 light works. I know theres a way to get them all to work(linkmessages?) but I know squat.

best world ...... touch once 1 light touch 2 2 light 3 =3 light 4 off

anyone have something like this? would gladly donate a few hundred L.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-14-2006 02:01
You could do it that way or have a dialog pop up and allow you to select which lights you want on.

I've no idea waht you current script is, I'm guessing its in each lamp and is something along the lines off :-

CODE

default
{
state_entry()
{
llSetAlpha(0,ALL_SIDES); // Make us invisible
}

// Touch activation
touch_start(integer total_number)
{
state state_on;
}


}
//--------------------------------------------------------------------------------------------------
state state_on
{
state_entry()
{
llSetAlpha(1,ALL_SIDES); // make the prim visible
}

touch_start(integer total_number)
{
state default;
}
}


To change it to turn then ALL on and OFF at once change the scripts to the following

CODE

default
{
state_entry()
{
llSetAlpha(0,ALL_SIDES); // Make us invisible
}

// Touch activation
touch_start(integer total_number)
{
llMessageLinked(LINK_ALL_OTHERS,0,"ON",NULL_KEY);
state state_on;
}

link_message(integer sender_num, integer num, string str, key id)
{
if("ON" == str) state state_on;
}
}
//--------------------------------------------------------------------------------------------------
state state_on
{
state_entry()
{
llSetAlpha(1,ALL_SIDES); // make the prim visible
}

touch_start(integer total_number)
{
llMessageLinked(LINK_ALL_OTHERS,0,"OFF",NULL_KEY);
state default;
}

link_message(integer sender_num, integer num, string str, key id)
{
if("OFF" == str) state default;
}
}


If you want to start getting fancy with selectable lights you will need to start playing around with object names or link numbers.
Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
12-14-2006 06:39
If all the light switches are within 100 meters of each other, you could have each one listening on an obscure channel.
when you switch on 1, it does llShout(CHANNEL, "off";);

the other switches hear "off" and change their state. Since prims cant hear their own shouts, you dont have to worry about shouting "on". Just set your on state locally in each switch.
Lyekahgood Nighbor
Registered User
Join date: 10 Aug 2006
Posts: 27
12-14-2006 13:15
thank you. Ill try that one. however here is the script I am using..

------------------------------------------------------------------------------------------------------
integer isOn = FALSE;
vector light_color;

integer listenHandle = 0;

// This makes it easier to change the light's parameters in one place
setLightParameters()
{
llSetPrimitiveParams ([PRIM_POINT_LIGHT , isOn , light_color , 1.0 , 10.0 , 0.75]);
}

default
{
on_rez(integer start_param)
{
llResetScript(); //Reset in case owner changed
}

state_entry()
{
light_color = llList2Vector(colorVectors , 0); //Set the initial color to white
}
touch_start(integer num_detected)
{
// If not already listening , start listening to the owner
if(listenHandle == 0)
{
listenHandle = llListen(channel_num , "" , llGetOwner() , "";);
llSetTimerEvent(30.0);
}
// Toggle the light on/off
isOn = !isOn;
// Set the light's parameters
setLightParameters();
}

timer()
{
// If the script is listening , stop listening and stop the timer to reduce lag
if(listenHandle != 0)
{
llListenRemove(listenHandle);
llSetTimerEvent(0.0);
}
}

listen(integer channel , string name , key id , string message)
{
// The following IF statement is for the paranoid :) Not really necessary to check the
// id against the owner , but no harm in doing it anyway
if(channel != channel_num || id != llGetOwner())
return;
// Look for what the user says in the list....
integer listLocation;
listLocation = llListFindList(colorWords , [message]);
// Did not find what the user said in the list? Stop here
if(listLocation == -1)
return;
// found what the user said in the list , set the corresponding vector
light_color = llList2Vector(colorVectors , listLocation);
// set the light's parameters - does not change On/Off setting
setLightParameters();
}
}

-----------------------------------------------------------------------------------------------

didnt know how to make the little box.
Lyekahgood Nighbor
Registered User
Join date: 10 Aug 2006
Posts: 27
12-14-2006 13:31
well....
that script makes stuff invisable... (which is cool in itself) but dosent really do anything for the lighting as far as I can work out. :(

L-
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
12-14-2006 14:01
From: Lyekahgood Nighbor
thank you. Ill try that one. however here is the script I am using..



Heyyy...that's my script :) (it's in the scripting library) Nice to see it making the rounds.

Extending the script to turn on other lights is easiest using link messages. Something like this in each light (not tested in-world):

CODE


default
{

link_message(integer sender, integer num,string msg, key id)
{
if(num == 10)
// turn the light on
else if(num == 20)
// turn the light off
}

}



Then, in the original script replace the setLightParameters function with this...

CODE


setLightParameters()
{
llSetPrimitiveParams ([PRIM_POINT_LIGHT , isOn , light_color , 1.0 , 10.0 , 0.75]);
integer linkNum=10;
if(!isOn) linkNum=20;
llMessageLinked(LINK_SET,linkNum,"",NULL_KEY);
}



One thing this won't do is set all of the lights to the same color.

Using llMessageLinked and link_message allows you to send some information, perhaps in the string parameter type - you can use that to communicate what color you want and the use llSetPrimitiveParams ([PRIM_POINT_LIGHT... to change the color and turn the light on/off.
Lyekahgood Nighbor
Registered User
Join date: 10 Aug 2006
Posts: 27
12-14-2006 15:29
sorry for not crediting you with the script. its a cool one.

but haveing issue with adding / changing the setlightparameters replacement.
I end up with syntax errors & not know squat I dont know what Im looking for in the way of errors.....

thanks again for eveyones assistance
L-
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-15-2006 03:39
From: Lyekahgood Nighbor
well....
that script makes stuff invisable... (which is cool in itself) but dosent really do anything for the lighting as far as I can work out. :(

L-



Sorry should have stated more clearly that that was an general example. It was to demonstrate the linked message rather than the lighting. The actual script was from a prim based light where it made a prim light cone appear and disappear.
Renee Roundfield
Registered User
Join date: 10 Mar 2006
Posts: 278
12-15-2006 09:55
Are you *sure* you want three light sources in one lamp?

You can make the second and third light bulbs "work" by turning them fill bright and adjusting hue if necessary. Still need to communicate with them for the function.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-15-2006 11:13
From: Renee Roundfield
Are you *sure* you want three light sources in one lamp?

You can make the second and third light bulbs "work" by turning them fill bright and adjusting hue if necessary. Still need to communicate with them for the function.



I'll agree with your concern here; the SL client only renders the 8 closest light sources I believe. it would be better to have a single light with the actual light source parameter, and the others set to full bright so that they appear lit, even though there's only 1 true light source. if the lights are close enough together (such as in a chandelier), this method would be ideal.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.