I have been making some lanterns for my new home in NFS and Sudane kindly gave me the script that allows for lights to automatically go on and off at sunrise/sunset.
In adapting it for my purposes, I came across the fact that Linden Labs no longer recommends that we use "llSetPrimitiveParams" (the main tool of the script) at all and has all but deprecated the function. Possibly this is not news to anyone else, lol. I've been out of the loop for a long time.
In any case, it is now suggested that we use a different function called "llSetLinkPrimitiveParamsFast" which entirely replaces the former function, and here is the kicker ... the new function executes 200 times faster!
I'm not a good enough scripter myself to know if this is anything to do with the lag that we sometimes experience in NFS, but 200 times faster seems like a good thing to me regardless so I re-wrote the light script using the new function.
These prim parameter setting functions are used in any script that changes the qualities (size, shape, light, glow, transparency, movement, shape, etc.) of a prim (one example would be the moving prim sculpture atop the Art Gallery) but lighting is one of our main uses. Again, I'm not knowledgeable enough to know if by "200 times faster" we are talking about reduced lag, but I figured I'd post the script here in case it was of use to anyone in the CDS.
The script assumes that the prim it sits in is either the *only* prim, or that if it's a linked set, it is the prim that's going to be the "lightbulb."
Script follows (the forum won't let me put it as an attachment so I'm posting it into the post):
PS - I am NOT the best scripter (by far!), so there may be mistakes although this seems to work for me.
// =========================
// Dianne's new light script
// =========================
//
// below are the qualities of the desired light source, all in one place for easy editing.
vector color = <0.965,0.718,0.694>; // red, green and blue values 0.00(dark) to 1.00(bright)
float intensity = 0.8; // % brightness: 0.0 to 1.0
float radius = 5.00; // range/distance of light: 0.0 to 20.0 meters
float falloff = 0.5; // % brightness at max distance 0.00 to 1.00
integer isON = FALSE; // makes sure we always start with the light off.
integer ownerKEY; // stores the owner's key so random people can't turn lights on/off.
// below are two functions to do the work of turning the light on/off. again, all in one place for easy editing.
// "llSetLinkPrimitiveParamsFast" can do a LOT of stuff, (best to look it up). For the light, all you need is the *first* line.
lightON()
{
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POINT_LIGHT, TRUE, color , intensity, radius, falloff]); // the light itself
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); // turns "bulb" fullbright
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.20 ]); // makes "bulb" glow
}
lightOFF()
{
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR , 0.0, 0.0, 0.0 ]);
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.0 ]);
}
// main script begins ...
default
{
state_entry()
{
llSetTimerEvent(1); // declare timer
}
timer()
{
llSetTimerEvent(360); // set timer
vector pos = llGetSunDirection();
if ( pos.z > 0 ){ // if sunrise or afterwards ...
lightOFF();
isON = FALSE;
}
else {
lightON();
isON = TRUE;
}
}
touch_start(integer total_number) // but if the owner touches the prim instead ...
{
if( llDetectedKey(ownerKEY) == llGetOwner() )
{
if (isON == TRUE){
lightOFF();
isON = FALSE;
}
else{
lightON();
isON = TRUE;
}
}
}
}