Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

lights at night

SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 06:20
Hi all,

I 'm looking into making a script that turns on my street light at night and off during the day. I basically need to turn the glow off and set the opacity during the day. Is that possible?
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
09-28-2009 06:50
The function you need to check if it's day or night is http://wiki.secondlife.com/wiki/LlGetSunDirection; there's an example there and plenty more at http://lslwiki.net/lslwiki/wakka.php?wakka=llGetSunDirection.

Basically, you use a timer to check llGetSunDirection every few minutes and then use llSetPrimitiveParams to turn the opacity, glow and whatever else on and off when the sun reaches the right point above or below the horizon.

If you search "daytime" in this forum, you should find plenty of discussions of the topic.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-28-2009 07:31
Try this one ...

CODE

// Spotlight ---- by Rolig Loon, April 2009
//
// This is a simple 3-prim spotlight, designed for outdoor use either as an individual light source or as part of a sim-wide lighting system.
// All lights controlled by this system in the sim go on/off within 5 minutes of the change from day to night or vice versa. In addition,
// the light beam can be turned on or off by saying the word "light" (lower case) on either channel 2 or channel 3. The keyword is a simple toggle.
// If the beam is ON, "light" turns it OFF, and vice versa.
//
// /2 light < < < < Turns THIS light ON or OFF. You must be within chat range of a light to activate it.
// /3 light < < < < Turns ALL lights like this in the same sim ON or OFF at the same time. You must be within chat range of at least ONE light to activate the system.
// NOTE: Because the keyword is a simple toggle, any light in the sim that is ON will be turned OFF, and vice versa.
// If you want individual lights turned ON or OFF, you will still have to activate them separately, using channel 2.
//

integer on;
integer night;
lighton()
{
llSetLinkAlpha(LINK_SET,0.0, ALL_SIDES);
}

lightoff()
{
llSetLinkAlpha(LINK_SET,1.0, ALL_SIDES);
llSetAlpha(0.3, ALL_SIDES);
}

default
{
state_entry()
{
llListen(2,"","","light");
llListen(3,"","","light");
llListen(-918273,"",NULL_KEY,"light");
on = FALSE;
llSetTimerEvent(300); // Check every 5 minutes
}
timer()
{
integer oldnight;
vector sun = llGetSunDirection();
if (sun.z <= 0) night = 1; // Sun is below the horizon
else if (sun.z > 0) night = 0; // Sun is above the horizon
if (night == oldnight) // If it's still night/day
{
if(on) lighton(); // Obey the light switch
else lightoff();
}
else if (night != oldnight) // If it's no longer night/day
{
if (on) lightoff(); // Turn light off
}
oldnight = night;
}

listen( integer channel, string name, key id, string message )
{
if(channel == 3)
{
llRegionSay(-918273,"light");
}
if (on) //If the light switch is on
{
lighton();
if (night == FALSE) on = !on;
}
else if (on == FALSE) //If light switch is off
{
lightoff();
if (night) on = !on;
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 08:10
what am I doing wrong here? I thought this would be simple but I obviously don't understand this stuff.


default
{
state_entry()
{
llSetTimerEvent(1); // Check every 1 second
}

timer()
{
vector sun = llGetSunDirection();
}

if (sun.z <= 0)
{ // If it is night, turn on ligh
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, 0 ] );

}

else if (sun.z > 0)
{ // If sun is Day turn off light
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, 1 ] );

}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-28-2009 09:27
You have a stray } right after you define the vector sun in your timer event. That has the effect of terminating the event. Move that } down to the bottom of your script and you'll be fine.

Incidentally, you really don't need to check the sun angle every second. It doesn't change that fast, and you're simply adding to sim load. Try testing once a minute or, as I did in my script, every five minutes. You're also using (ICK!) glow as your light, which many people find abhorrent. I'd suggest using full bright instead. It's less garish and looks much more like a light bulb.

BTW, the reason you don't see full bright in my script is that I am using llSetAlpha to make a spotlight beam visible/invisible as I go from day to night or vice versa. My beam is simply a hollow phantom cone with a white texture that grades from about 80% opaque at the light source (the pointy end of the cone) to 10% opaque at the other end. The script is in the cone, which is the root prim of my spotlight fixture. The lighton function switches the entire fixture to 100% opaque and then sets the cone to 30% opaque. That, combined with the graded alpha texture, gives me a pleasingly soft spotlight beam. The bulb itself is always full bright. When the lightoff function is activated, the entire fixture is invisible. If you wanted to use full bright instead, you'd just have to recode my lighton and lightoff functions.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 10:09
Well right now I have the time set to 1 second for testing. I got it compiled in this version and it turns on at night but when I change back to daytime it don't work. What am I doing wrong now? When I have the script at least turning on and off the way I want it I will play around with the transparency and full bright settings to get the overall best look but for now I'm simply testing things out as simple as possible so I don't confuse myself to much.

default
{


state_entry()
{
llSetTimerEvent(1); // Check every 1 second


}


timer()
{
vector sun = llGetSunDirection();
if (sun.z >= 0)
{ // If sun is Day turn off light
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, .05] );
llSay(0,"Turn off Light";);

}
else
{
llSay(0,"Turn on Light";);
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, 0 ] );

}
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-28-2009 10:18
If you're doing the testing on your own sim, you can turn night on and off in the World >> Estate settings. That's really the only way to test, so if you don't own the sim or have manager level privileges, you're screwed. . If you change from day to night in your World >> Environment settings, the change only takes place in your own client. The sim is unaffected, so the light doesn't see a change in sun angle.

ETA: BTW, it looks as if you set glow to 0.05 if sun.z >0..... daytime .... and set it to 0 at night. That's backwards.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 10:24
well I am testing it using the environment manager and its only turning on its like the "Else" part of the code is not working.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-28-2009 11:11
So it's not even saying "Turn on light"?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 11:16
no it don't even say turn on light.

default
{


state_entry()
{
llSetTimerEvent(1); // Check every 1 second


}


timer()
{
vector sun = llGetSunDirection();
if (sun.z >= 0) // If sun is Day turn off light
{
llSetPrimitiveParams( [ PRIM_FULLBRIGHT, ALL_SIDES, 0 ] );
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, .0 ] );
llSetPrimitiveParams([ PRIM_TEXTURE, ALL_SIDES, TEXTURE_TRANSPARENT, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);

llSay(0,"Turn off Light";);
}



else
{

llSetPrimitiveParams( [ PRIM_FULLBRIGHT, ALL_SIDES, 1 ] );
llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, .05 ] );
llSetPrimitiveParams([ PRIM_TEXTURE, ALL_SIDES, TEXTURE_BLANK, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);

llSay(0,"Turn on Light";);
}


}
}
SirFency Blackheart
Registered User
Join date: 6 Jan 2009
Posts: 81
09-28-2009 12:29
I got it working. Thanks for the help!
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-28-2009 12:38
I think it might already have been working; I tried it in a hud at a few fixed-sun sims, and I observed the dawn thus:

[12:34] Object: Turn on Light
[12:34] Object: Turn on Light
[12:35] Object: Turn on Light
[12:35] Object: Turn off Light
[12:35] Object: Turn off Light
[12:35] Object: Turn off Light