Keeps track if the sun in a region is day or night.
You can use this script to turn a light on automatically when it becomes night time and off in the day. Just add your script snippets where it says "Do something here" below.
integer time = 120; //How many seconds between checking
integer IsDay;
Check()
{
vector sun_dir = llGetSunDirection(); //gets sun direction
if (sun_dir.z > 0 && IsDay == FALSE) //a positive value for sun_dir.z means its daytime
{
IsDay = TRUE;
//Do something here for when it is day.
}
else if (sun_dir.z < 0 && IsDay == TRUE) //a negative value for sun_dir.z means its nighttime
{
IsDay = FALSE;
//Do something here for when it is night.
}
}
default
{
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
vector sun_dir = llGetSunDirection();
IsDay = (sun_dir.z < 0);
Check();
llSetTimerEvent(time);
}
timer()
{
Check(); //this calls the function to check the day / night status
}
touch_start(integer total_number) //only for debug - can be removed
{
Check();
if (IsDay == TRUE)
{
llSay(0, "It is currently day.");
}
else
{
llSay(0, "It is currently night.");
}
}
}
|