Jump to content

Best Method To Find Out If Its 12AM


queenkhaleesi
 Share

You are about to reply to a thread that has been inactive for 3742 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Use wall clock found here:

http://wiki.secondlife.com/wiki/LlGetWallclock

 

Quick sample:

// Convert to human-readable HH:MM:SS format
string ConvertWallclockToTime()
{
    integer now = (integer)llGetWallclock();
    integer timezone = - 16; //GMT (Takes 16 hours from current time)
    integer seconds = now % 60; //seconds
    integer minutes = (now / 60) % 60; //Minutes
    integer hours = now / 3600; //Hours
    integer hourswtimezone = hours + timezone; //takes timezone from current hours
    return llGetSubString("0" + (string)hourswtimezone, -2, -1) + ":"
        + llGetSubString("0" + (string)minutes, -2, -1) + ":"
        + llGetSubString("0" + (string)seconds, -2, -1);
}
 
default
{
    touch_start(integer total_number)
    {
        llSay(0, ConvertWallclockToTime());
    }
}


I made this quick so there may be errors but should give you an idea.

 

You would want ot convert this to a loop on rez and look to see if the hours equal 12 (or 00:00)

Link to comment
Share on other sites

Can't sleep so here...

string is12() //STRING COMMAND NAME
{
    integer now = (integer)llGetWallclock(); //SETS NOW AS CURRENT TIME
    integer hours = now / 3600; //TURNS HOURS IN TO 24H FORMAT
    string es = llGetSubString("0" + (string)hours, -2, -1); //ADDS 0 IF ONE DIG
    return llDeleteSubString(es, -3, -3); //REMOVES - IF HOURS IN NEG (GOOD IF MAKING TIME ZONE)
}

default //MAIN SCRIPT
{
    state_entry() //FIRST STARTS
    {
        llSetTimerEvent(60); // Activate the timer every 60 seconds (DONT WANT ANY QUICKER OR MAY ACTIVATE TWICE)
    }
    
     timer() //LOOPS EVREY 60 SECONDS
     {
         if (is12() == "00") //IS CURRENT HOUR 12 AM
         {
         //ADD THING TO ACTIVATE AT 12AM HERE:
         llSay(0,"Another Day!"); //SAY ON PUBLIC CHAT THAT ITS A NEW DAY
         }
    }
    
    
    touch_start(integer total_number) // ON TOUCH
    {
        llSay(0,"The Current Hour is " + is12() + "."); //TELL TIME (GOOD TO SEE IF WORKING)
    }
    
}

Link to comment
Share on other sites

12AM being midnight, the most simple test is to test when the day changes from one date to another using llGetDate()

string dayLast;float checkRate = 60.0;default{    state_entry()    {        dayLast = llGetSubString( llGetDate(), -2, -1);        llSetTimerEvent( checkRate);    }    timer()    {        string dayNow = llGetSubString( llGetDate(), -2, -1);        if ( dayNow != dayLast )        {            // past midnight            llOwnerSay( "The new day is: "+dayNow);        }        dayLast = dayNow;        llOwnerSay( "Day is: "+dayNow); // for testing    }}

This of course is 12AM in the UTC time zone
Anyway it happens one time every 24 hours no matter what time zone you are in

Link to comment
Share on other sites


Killian Jayaram wrote:

Can't sleep so here...

 

string is12() //STRING COMMAND NAME

{

    integer now = (integer)llGetWallclock(); //SETS NOW AS CURRENT TIME

    integer hours = now / 3600; //TURNS HOURS IN TO 24H FORMAT

    string es = llGetSubString("0" + (string)hours, -2, -1); //ADDS 0 IF ONE DIG

    return llDeleteSubString(es, -3, -3); //REMOVES - IF HOURS IN NEG (GOOD IF MAKING TIME ZONE)

}

 

default //MAIN SCRIPT

{

    state_entry() //FIRST STARTS

    {

        llSetTimerEvent(60); // Activate the timer every 60 seconds (DONT WANT ANY QUICKER OR MAY ACTIVATE TWICE)

    }

    

     timer() //LOOPS EVREY 60 SECONDS

     {

         if (is12() == "00") //IS CURRENT HOUR 12 AM

         {

         //ADD THING TO ACTIVATE AT 12AM HERE:

         llSay(0,"Another Day!"); //SAY ON PUBLIC CHAT THAT ITS A NEW DAY

         }

    }

    

    

    touch_start(integer total_number) // ON TOUCH

    {

        llSay(0,"The Current Hour is " + is12() + "."); //TELL TIME (GOOD TO SEE IF WORKING)

    }

    

}

Unsure why you're concerned with it activating twice when the code you have there goes off 60 times the first hour of each day.

 

// Does not account for daylight savings time changes through the year.

default{ state_entry() { llSetTimerEvent(86400 - llGetWallclock()); // set timer for midnight SLT } timer() { llSetTimerEvent(86400); // set timer for 24 hours later //ADD THING TO ACTIVATE AT 12AM HERE: llSay(0,"Another Day!"); //SAY ON PUBLIC CHAT THAT ITS A NEW DAY }}

 

Link to comment
Share on other sites

Good point:


// Does not account for daylight savings time changes through the year.default{ state_entry() { llSetTimerEvent(86400 - llGetWallclock()); // set timer for midnight SLT } changed(integer change) { if (change & CHANGED_REGION_START) llSetTimerEvent(86400 - llGetWallclock()); // set timer for midnight SLT } timer() { llSetTimerEvent(86400); // set timer for 24 hours later //ADD THING TO ACTIVATE AT 12AM HERE: llSay(0,"Another Day!"); //SAY ON PUBLIC CHAT THAT ITS A NEW DAY }}

 Anything to get away from checking every minute for a once in every 24 hour action!

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3742 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...