Jump to content

Script to control two lights simultaneously


Coby Foden
 Share

You are about to reply to a thread that has been inactive for 2044 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have a script which controls light (On/Off) in one prim. What I would need is a script which turns light on/off at the same time in two linked prims when clicking either prim in the linkset. Now I have the script in both prims in the linkset. Unfortunately the LI is 2 this way even when both prims are set to convex hull. If the script is only in the root prim then the LI is 1. And that's what I'm after as I live in Linden home with LI allowance of only 175. So every saved LI is precious (I have many local lights in the house). The script what I have is:
- - - - -
integer isLightTurnedOn;
 
default
{
    touch_start(integer total_number)
    {
//      toggle isLightTurnedOn between TRUE and FALSE
        isLightTurnedOn = !isLightTurnedOn;
 
        if (isLightTurnedOn)
        {
            llSetPrimitiveParams([
                PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
                PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.31, 6.0, 0.35]);
        }
        else
        {
            vector COLOR_ORANGE  = <0.998, 0.854, 0.995>;
 
            llSetPrimitiveParams([
                PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
                PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 0.31, 6.0, 0.35]);
        }
    }
}
- - - - -

Something simple should be added to the script so that it would work as I want it to work. As I'm total newbie in scripting I have no idea what to add there. Maybe somebody could show me what to add there. Thank you.

Link to comment
Share on other sites

integer isLightTurnedOn;
 
default
{
    touch_start(integer total_number)
    {
//      toggle isLightTurnedOn between TRUE and FALSE
        isLightTurnedOn = !isLightTurnedOn;
 
        if (isLightTurnedOn)
        {
            llSetLinkPrimitiveParamsFast(LINK_SET, [ 34, 1,  PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
                PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.31, 6.0, 0.35, 34, 2, PRIM_FULLBRIGHT,
                ALL_SIDES, FALSE,  PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.31, 6.0, 0.35]);
        }
        else
        {
            vector COLOR_ORANGE  = <0.998, 0.854, 0.995>; 
            llSetLinkPrimitiveParamsFast(LINK_SET, [  34, 1,  PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
                PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 0.31, 6.0, 0.35,   34, 2,  PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
                PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 0.31, 6.0, 0.35]);
        }
    }
}

That ought to work, if you put it in the root prim.  You could make this script more compact, of course, but there's no real need to unless you like compactness.  ;)

BTW, I am assuming that there are only two links in the linkset.  If there's more than that, we ought to have a little safeguard to keep the wrong ones from lighting up.

Edited by Rolig Loon
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Rolig's answer assumes that the linkset comprises two objects (and only two), both of which are lights which turn on and off simultaneously.  

I read it rather differently, and took it to mean that the linkset includes several objects, two of which are lights that turn on and off, while the other links aren't affected.   In the circumstances I've described, one way to do it is to name the two objects you want to affect "Light Bulb" or whatever and then do something like this:

integer iIsLightTurnedOn;
vector COLOR_ORANGE = <0.998, 0.854, 0.995>;
  
list lLightOn =[
	PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
	PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.31, 6.0, 0.35
		];
list lLightOff =[
	PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
	PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 0.31, 6.0, 0.35
		];




default
{
	state_entry()
	{
	}
	touch_start(integer total_number)
	{
		integer max = llGetNumberOfPrims() + 1;
		integer counter = 1;
		list lParams;
		list lTemp = lLightOn;
		if(iIsLightTurnedOn=!iIsLightTurnedOn){
			lTemp = lLightOff;
		}
		do {
			if("Light Bulb" == llGetLinkName(counter)){
				lParams +=[PRIM_LINK_TARGET, counter]+ lTemp;
			}
		}
		while (++counter < max);
		llSetLinkPrimitiveParamsFast(LINK_SET,lParams);
	}
}

Not tested it but I think it should work.

ETA Tested it now and it works after I corrected a typo in lParams +=[PRIM_LINK_TARGET,  counter] + lTemp; and also moved the declaration of COLOR_ORANGE to make script compile in world.

Edited by Innula Zenovka
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2044 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...