Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
11-14-2005 04:52
I've written a simple isNight() function, but the way things are looking I won't be on SL when it's supposed to trigger so I can't be certain if it works. So I'm gonna post it here to see if anyone can tell me if it will work or not, or if someone can test it for me that would be neat! integer isNight() { integer time = (integer)llGetTimeOfDay(); if ((time < 1800) || (time > 12600)) return TRUE; return FALSE; } Quite simply this checks the time of day and works out if it is the night time hour (half an hour before and half an hour after midnight, a time of zero). I'm using this in a simple script which causes some nice colour-changing lights to come on when it's night time, I'll likely adjust the numbers to suit as I'm uncertain when exactly it starts getting dark so don't know the best time to switch them on. But this works for a raw night-time test, or at least, I hope it does!
|
Alexis Ingersoll
Registered User
Join date: 26 Jan 2005
Posts: 14
|
11-14-2005 05:08
Hi Haravikk! This is a nice script, and I like the inherent simplicity of it. For an alternative approach, you may be interested in looking at this thread: /8/a0/3288/1.htmlThe short story is that there is a built-in function which checks where the sun is at in the sky, which will tell precisely whether it's light or dark. That gives a nice second way of solving the problem. Good luck with your lights! Please let us know how things work out for you. 
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
11-14-2005 08:40
Got them working great, they look awesome at night =) The function I used seems to be about right actually, I'll look into the sun direction method as well though as it may be more precise.
Thanks!
|
Sean Gorham
Stopped making sense
Join date: 5 Mar 2005
Posts: 229
|
11-14-2005 09:51
http://secondlife.com/badgeo/wakka.php?wakka=llGetSunDirectionI used something like the following in some automatic lights I made recently. I'm typing this from memory as I'm not in-world at the moment. // Check the sun's position every 5 minutes. float SUN_CHECK_INTERVAL = 300.0;
// When the sun is 5 degrees above the horizon, it's "dark". float SUN_DOWN_THRESHOLD = 5.0;
default { state_entry() { llSetTimerEvent(SUN_CHECK_INTERVAL); } timer() { vector sun = llGetSunDirection(); if(sun.z <= llSin(SUN_DOWN_THRESHOLD * DEG_TO_RAD)) { // "sun is down" code goes here } else { // "sun is up" code goes here } } } In the code above, sun.z will always be a number between -1 and 1. At 1 the sun is directly overhead; at -1 the sun is straight down and the moon is straight up. You can figure out the exact angle of the sun by taking the arcsine of the number. Optionally, you may want to add a global boolean for the sun's state so you don't execute the code in the timer() handler every time it fires. In my experience it's easier to use llGetSunDirection() for any kind of "automatic light" type of function. The sun's position can be fixed into an arbitrary position. This is true even on the mainland, although there only the Lindens can do it. They did so on Halloween for several hours so everybody could get a view of Jason-Voorhees-in-the-Moon. 
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-14-2005 11:52
llGetTimeOfDay cannot be used for reliably detecting the sims time of day for two reasons. 1. llGetTimeOfDay resets to zero on sim crash. 2. If you are on a private island where the sun is fixed llGetTimeOfDay never resets.
If you want to know the time, use the 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
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
11-14-2005 12:19
How does this interact with a client-side force sunset? If a client uses that command, will it be daytime for the client, but still night-time on the sim so the lights stay on? Or does it work differently?
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
11-14-2005 14:21
If the client forces something via debug commands, the Sim doesn't know about it. so scripts won't know.
Technically the moon is NOT directly opposite the sun. Lindens report that sometime around 3020 AD there will be an eclipse
|