Day/Night Script

Date 2010/5/12 5:16:41 | Topic: Time

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.&& 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.&& 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.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.");
        }
    }
}




This script comes from Alicia Stella Design - Best Tip Jars in Second Life
http://www.aliciastella.com

The URL for this script is:
http://www.aliciastella.com/modules/AMS/article.php?storyid=39