Difference between revisions of "LlGetWallclock"

From Second Life Wiki
Jump to navigation Jump to search
m (added an example of converting seconds to an HH:MM:SS string)
m
Line 9: Line 9:
|constants
|constants
|examples=<lsl>// Real World Sun
|examples=<lsl>// Real World Sun
integer set;
integer Flag;


default
default
Line 15: Line 15:
     state_entry()
     state_entry()
     {
     {
        Flag = -1;
         llSetTimerEvent(0.1);
         llSetTimerEvent(0.1);
        set = -1;
     }
     }
      
      
Line 22: Line 22:
     {
     {
         float time = llGetWallclock();
         float time = llGetWallclock();
         if(set == -1)
         if (Flag == -1)
        {
             llSetTimerEvent(60.0);
             llSetTimerEvent(60.0);
         if(time < 21600)
        }
         if (time < 21600)
         {
         {
             if(set)
             if (Flag)
             {
             {
                 llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
                 llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
                 set = 0;
                 Flag = 0;
             }
             }
         }
         }
         else if(time < 64800)
         else if (time < 64800)
         {
         {
             if(set != 1)
             if (Flag != 1)
             {
             {
                 llSetText("Sun has risen. :(", <1,0,0>, 1.0);
                 llSetText("Sun has risen. :(", <1,0,0>, 1.0);
                 set = 1;
                 Flag = 1;
             }
             }
         }
         }
         else if(set != 2)
         else if (Flag != 2)
         {
         {
             llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
             llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
             set = 2;
             Flag = 2;
         }
         }
     }
     }
Line 49: Line 51:


<lsl>// Convert to human-readable HH:MM:SS format
<lsl>// Convert to human-readable HH:MM:SS format
string ConvertWallclockToTime (float now)
string ConvertWallclockToTime(float wall_clock)
{
{
     integer iNow = (integer) now;
     integer now = (integer)wall_clock;
     integer seconds = iNow % 60;
     integer seconds = now % 60;
     integer minutes = ((iNow - seconds) % 3600) / 60;
     integer minutes = ((now - seconds) % 3600) / 60;
     integer hours = (iNow - minutes - seconds) / 3600;
     integer hours = (now - minutes - seconds) / 3600;
     string result = (string) seconds;
     return llGetSubString("0" + (string)hours, -2, -1) + ":"  
    if (seconds < 10)
        + llGetSubString("0" + (string)minutes, -2, -1) + ":"  
        result = "0" + result;
        + llGetSubString("0" + (string)seconds, -2, -1);
    result = (string)minutes + ":" + result;
    if (minutes < 10)
        result = "0" + result;
    result = (string)hours + ":" + result;
    if (hours< 10)
        result = "0" + result;
    return result;
}
}



Revision as of 02:44, 26 October 2010

Summary

Function: float llGetWallclock( );
0.0 Forced Delay
10.0 Energy

Returns a float that is the time in seconds since midnight Pacific time (PST/PDT), truncated to whole seconds.

For GMT use llGetGMTclock

Examples

<lsl>// Real World Sun integer Flag;

default {

   state_entry()
   {
       Flag = -1;
       llSetTimerEvent(0.1);
   }
   
   timer()
   {
       float time = llGetWallclock();
       if (Flag == -1)
       {
           llSetTimerEvent(60.0);
       }
       if (time < 21600)
       {
           if (Flag)
           {
               llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
               Flag = 0;
           }
       }
       else if (time < 64800)
       {
           if (Flag != 1)
           {
               llSetText("Sun has risen. :(", <1,0,0>, 1.0);
               Flag = 1;
           }
       }
       else if (Flag != 2)
       {
           llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
           Flag = 2;
       }
   }

}</lsl>

<lsl>// Convert to human-readable HH:MM:SS format string ConvertWallclockToTime(float wall_clock) {

   integer now = (integer)wall_clock;
   integer seconds = now % 60;
   integer minutes = ((now - seconds) % 3600) / 60;
   integer hours = (now - minutes - seconds) / 3600;
   return llGetSubString("0" + (string)hours, -2, -1) + ":" 
       + llGetSubString("0" + (string)minutes, -2, -1) + ":" 
       + llGetSubString("0" + (string)seconds, -2, -1);

}

default {

   touch_start(integer total_number)
   {
       ConvertWallclockToTime(llGetWallclock());
   }

}

</lsl>

See Also

Functions

•  llGetGMTclock Seconds since midnight GMT

Deep Notes

Signature

function float llGetWallclock();