Adding Full Bright to Light Script

Creating scripts
Post Reply
User avatar
Natalie Oe
Posts: 32
Joined: Mon May 07, 2018 10:15 am
Has thanked: 18 times
Been thanked: 16 times
Contact:

Adding Full Bright to Light Script

Post by Natalie Oe » Fri May 24, 2019 2:25 pm

Hi All,

Wondering if anyone can help. I have a light script (posted below) its controlled via a remote switch and all works great. However, I would like the light bulb to also switch to full bright when on and switch off when the light is off. I tried to do it myself but just got a massive headache. I'm happy to compensate for the minor adjustment if necessary.

Here is the bulb script:

Code: Select all

//Simple remote light by Adelle Fitzgerald. Use as you like but please keep this header.

integer channel = 20; //Set this to the same channel as your switch. If you want to operate more than one light individually then set to a diffetent channel (not 0) and set the same channel in the switch script
float intensity = 1.0; //Set this to the brightness of the light (0.0 - 1.0)
float radius = 5; //Set this to the light radius in meters (0.0 - 20.0)
float falloff = 2.0; //Set this to the falloff of the light (0.0 - 2.0)
vector colour = <1,1,1>; //colour of the light <R,G,B> (0.0 - 1.0)

default
{
    state_entry()
    {
        llListen(channel,"","","");
    }
    
    listen (integer channel, string name, key id, string message)
    {
        if (message == "on")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,colour,intensity,radius,falloff]);
        }
        if (message == "off")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,colour,intensity,radius,falloff]);
        }
    }    
}
These users thanked the author Natalie Oe for the post (total 2):
Ilan TochnerZed deTremont
Graham Mills
Posts: 996
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 603 times
Been thanked: 751 times

Re: Adding Full Bright to Light Script

Post by Graham Mills » Fri May 24, 2019 6:03 pm

Like this?

Code: Select all

//Simple remote light by Adelle Fitzgerald. Use as you like but please keep this header.

integer channel = 20; //Set this to the same channel as your switch. If you want to operate more than one light individually then set to a diffetent channel (not 0) and set the same channel in the switch script
float intensity = 1.0; //Set this to the brightness of the light (0.0 - 1.0)
float radius = 5; //Set this to the light radius in meters (0.0 - 20.0)
float falloff = 2.0; //Set this to the falloff of the light (0.0 - 2.0)
vector colour = <1,1,1>; //colour of the light <R,G,B> (0.0 - 1.0)

default
{
    state_entry()
    {
        llListen(channel,"","","");
    }
    
    listen (integer channel, string name, key id, string message)
    {
        if (message == "on")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,colour,intensity,radius,falloff, PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);
            
        }
        if (message == "off")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,colour,intensity,radius,falloff, PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);
        }
    }    
}
These users thanked the author Graham Mills for the post (total 2):
Natalie OeZed deTremont
User avatar
Natalie Oe
Posts: 32
Joined: Mon May 07, 2018 10:15 am
Has thanked: 18 times
Been thanked: 16 times
Contact:

Re: Adding Full Bright to Light Script

Post by Natalie Oe » Sat May 25, 2019 5:14 am

Thank you so very much Graham. That was exactly what I was looking for.
These users thanked the author Natalie Oe for the post:
Graham Mills
User avatar
Brayla Sana
Posts: 67
Joined: Wed Mar 27, 2013 7:09 pm
Has thanked: 16 times
Been thanked: 112 times

Re: Adding Full Bright to Light Script

Post by Brayla Sana » Mon May 27, 2019 11:56 am

I want to make this a bit more efficient for you, because it looks like you want to use it in your builds.
See this thread viewtopic.php?t=1149 on why I replaced llSetPrimitiveParams([]); with llSetLinkPrimitiveParamsFast(LINK_THIS,[]);

Code: Select all

// Simple remote light by Adelle Fitzgerald. Use as you like but please keep this header.
// Brayla changed the LSL function to a better one.

integer channel = 20; //Set this to the same channel as your switch. If you want to operate more than one light individually then set to a different channel (not 0) and set the same channel in the switch script
float intensity = 1.0; //Set this to the brightness of the light (0.0 - 1.0)
float radius = 5; //Set this to the light radius in meters (0.0 - 20.0)
float falloff = 2.0; //Set this to the falloff of the light (0.0 - 2.0)
vector colour = <1,1,1>; //colour of the light <R,G,B> (0.0 - 1.0)

default
{
    state_entry()
    {
        llListen(channel,"","","");
    }
    
    listen (integer channel, string name, key id, string message)
    {
        if (message == "on")
        {
            llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POINT_LIGHT,TRUE,colour,intensity,radius,falloff]);
        }
        if (message == "off")
        {
            llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POINT_LIGHT,FALSE,colour,intensity,radius,falloff]);
        }
    }    
}
You will also want to change the channel to a negative number; only scripts can use negative chat channels and this reduces potential conflicts with chat channels used by the viewer.
These users thanked the author Brayla Sana for the post (total 2):
Graham MillsNatalie Oe
Dadiella's for Fashion and Brayla Sana Gallery for Building!
User avatar
Natalie Oe
Posts: 32
Joined: Mon May 07, 2018 10:15 am
Has thanked: 18 times
Been thanked: 16 times
Contact:

Re: Adding Full Bright to Light Script

Post by Natalie Oe » Sat Jun 01, 2019 11:28 pm

Thank you Brayla!!
Post Reply