Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Question about llGetSunDirection

Drizzt Naumova
Teh Foxeh DJ
Join date: 9 Oct 2005
Posts: 116
03-10-2006 04:04
Greetings.
I was wondering if someone could help me. I am wanting to make me a pair of sunglasses that will appear and dissappear according to the sun's position..like say at sunrise they will appear and at sunset dissapear and also have like a chat message on channel 0 that i can enter into the script according to the sun's position as well. I know this will use the llGetSunDirection, llSetAlpha and also llSay on channel 0 for the chat message. I tried tinkering around with the below script, but I'm not that script savvy. Any ideas?
CODE

default {
state_entry() {
llSetTimerEvent(4);
}
timer() {
vector sun = llGetSunDirection();
if(sun.z > 0) {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llSetPrimitiveParams([PRIM_PHANTOM, TRUE]);
llSetAlpha(0.01, ALL_SIDES);
}
else {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llSetPrimitiveParams([PRIM_PHANTOM, TRUE]);
llSetAlpha(0.20, ALL_SIDES);
}
}
}
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-10-2006 04:23
Well, the basic check is sound, checking sun.z > 0 for sun above the horizon. However, it's going to set the parameters for the sunglasses every four seconds, regardless of whether the sun's been up for hours! That's wasteful, and that timer is unnecessarily rapid as well I'd say. I'd set it to at least ten seconds.

If you just want the sunglasses to appear at sunrise and disappear at sunset, then try the following control script:
CODE
integer gSunUp = TRUE;

default
{
state_entry()
{
llSetTimerEvent(5.0);
}

timer()
{
vector sun = llGetSunDirection();
if (gSunUp) {
if(sun.z <= 0) {
// Sunset
gSunUp = FALSE;
llMessageLinked(LINK_SET, 0, "", NULL_KEY);
}
}
else if (sun.z > 0) {
// Sunrise
gSunUp = TRUE;
llMessageLinked(LINK_SET, 1, "", NULL_KEY);
}
}
}

and then the following in all prims of the object
CODE
default
{
link_message(integer s, integer n, string msg, key id)
{
if (n == 0) llSetAlpha(0.0, ALL_SIDES);
else if (n == 1) llSetAlpha(1.0, ALL_SIDES);
}
}

(or with different llSetAlpha parameter if some of them are going to be at different alphas). As for the chat message, well, that is going to depend on what it is and when you want it.

edit: as below, if you want to entire object to flip between 100% and 0% alpha, llSetLinkAlpha is better!
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-10-2006 04:25
I'm not 100% sure what you're after (and why do you want it to say something and why?) but you could try something like:
CODE

integer dark;
default {
state_entry() {
llSetTimerEvent(4);
}
timer() {
vector sun = llGetSunDirection();
if(sun.z > 0) { //Check the sun is up!
if(dark) //Check we've not already changed for sun up
{
dark=FALSE;
llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES); //make the glasses appear
llOwnerSay("Dawn"); //Say it's dawn
}
}
else {
if(!dark)
{
dark=TRUE;
llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); //Glasses vanish
llOwnerSay("Dusk"); //Just like above...
}
}
}
}

There was lots of other random bits in your code - and this might not be 100% suitable depending on how you've built your sunglasses. For example, it assumes the lenses are built with a suitably alphaed texture rather than using inworld transparency to work them. If that's not the case you might need to consider linked messages instead.

This also means the glasses don't change every few seconds, just at sunrise and sunset. This could also be done with states and other things, but it works this way just fine!
Drizzt Naumova
Teh Foxeh DJ
Join date: 9 Oct 2005
Posts: 116
03-10-2006 06:30
Thanxx for both replies. both will be very helpful i am sure. :)
Like you said with the setalpha on the lenses of the glasses, i can prolly tinker around with the alpha setting in the script and put the altered scripts in the lenses so that they have a diff effect other than the rest of the sunglasses (i.e the ear, nosepeice and lens frame)
Thanxx again you 2 for the excellent feedback. you will both be getting a pos. rating in game :)
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
03-10-2006 06:42
Perhaps change the timer to something a bit longer-- say, a minute? There's no need to check every 5 seconds.
Drizzt Naumova
Teh Foxeh DJ
Join date: 9 Oct 2005
Posts: 116
03-10-2006 10:16
already ahead of ya :P set it to check every 4 minutes :)
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
03-10-2006 10:45
You should be able to calculate the time of sunset or sunrise from the sun direction, and have it only "check" then.
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
03-10-2006 11:29
yes and no to only checking when it's suppose to rise or set. Problem is you would basically adjust your timer out to how long until the next rise or set event, but the timer resets to zero when you change regions. so, when you change regions, you need to reset your timer again. So ya it can be done, just remember that gotcha :).
_____________________
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
03-11-2006 08:03
And you would still have to have a timer to see if it was the right "time" to check . . . would that be any different? You check simtime or you check sunangle.

Baron
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
03-11-2006 10:01
Well, you'd only be having the timer go off twice in four hours instead of several hundred times.

It's only a little things, but lots of little things add up to lag.

But if you have to check periodically because of sim crossings, every four minutes plus after teleporting seems reasonable.
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
03-11-2006 14:43
What I'm saying, though, is that the script does not know what time it is without checking, does it? So you still have to check every so often to see if it is the right "time" for the sun to be going up/down. Or am I missing something really obvious (I'm not discounting that possibility!!!)

Baron
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
03-11-2006 16:43
From: Baron Hauptmann
What I'm saying, though, is that the script does not know what time it is without checking, does it?
That's right, but it can calculate the time of sunset or sunrise from the sun direction. So for an object that stays in the same sim it only needs to check when it's first rezzed... then it can calculate the time of next sunrise/set and set a timer to go off then, and continue to calculate the next time each time it's rezzed or the timer goes off.

It's the region changes that cause the problem. Not only are timers reset, but different sims can have different sunrise/set times.
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
03-11-2006 20:42
Ah. I see now. That makes perfect sense. Check the sun direction, calculate the next sunrise/sunset, pass that value to the timer, and stand back. Sometimes it is hard to get one's brain out of a rut.

Baron
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
03-16-2006 02:57
And now we have CHANGED_REGION and CHANGED_TELEPORT in the changed event :)
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-16-2006 04:13
llGetRegionFlags
REGION_FLAG_FIXED_SUN
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey