Difference between revisions of "LlGetDayOffset"

From Second Life Wiki
Jump to: navigation, search
(Created page with "{{LSL_Function |func=llGetDayOffset|return_type=integer |func_desc=Return the number of seconds added to the current time before calculating the current environmental time for...")
 
(Add an example script showing the current parcel time)
Line 2: Line 2:
 
|func=llGetDayOffset|return_type=integer
 
|func=llGetDayOffset|return_type=integer
 
|func_desc=Return the number of seconds added to the current time before calculating the current environmental time for the parcel.  [[llGetDayOffset ]] returns the value for the current parcel, [[llGetRegionDayOffset]] produces the same value for the entire region.
 
|func_desc=Return the number of seconds added to the current time before calculating the current environmental time for the parcel.  [[llGetDayOffset ]] returns the value for the current parcel, [[llGetRegionDayOffset]] produces the same value for the entire region.
 +
|examples=
 +
<source lang="lsl2">
 +
// print the apparent time of day as HH:MM (%), just like the environment window viewer.
 +
// Time of day is a fraction between 0 and 1, 0 is midnight, 0.5 is noon
 +
string printTimeOfDay(float dayFraction) {
 +
    integer hours = (integer)(dayFraction * 24);
 +
    integer minutes = (integer)(dayFraction * 24 * 60) % 60;
 +
    integer percent = (integer)(dayFraction * 100);
 +
    return (string)hours + ":" + llGetSubString((string)(100+minutes), 1, 2) + " (" + (string)percent + "%)";
 +
}
 +
 +
default {
 +
    state_entry() {
 +
        llSetTimerEvent(5);
 +
    }
 +
 +
    timer() {
 +
        float timeOfDay = (llGetUnixTime() + llGetDayOffset()) % llGetDayLength() * 1.0 / llGetDayLength();
 +
        llSetText(printTimeOfDay(timeOfDay), <1,1,0>, 1);
 +
    }
 +
}
 +
</source>
  
 
|also_functions=
 
|also_functions=

Revision as of 21:23, 13 May 2020

Summary

Function: integer llGetDayOffset( );

Return the number of seconds added to the current time before calculating the current environmental time for the parcel. llGetDayOffset returns the value for the current parcel, llGetRegionDayOffset produces the same value for the entire region.
Returns an integer

Examples

// print the apparent time of day as HH:MM (%), just like the environment window viewer.
// Time of day is a fraction between 0 and 1, 0 is midnight, 0.5 is noon
string printTimeOfDay(float dayFraction) {
    integer hours = (integer)(dayFraction * 24);
    integer minutes = (integer)(dayFraction * 24 * 60) % 60;
    integer percent = (integer)(dayFraction * 100);
    return (string)hours + ":" + llGetSubString((string)(100+minutes), 1, 2) + " (" + (string)percent + "%)";
}
 
default {
    state_entry() {
        llSetTimerEvent(5);
    }
 
    timer() {
        float timeOfDay = (llGetUnixTime() + llGetDayOffset()) % llGetDayLength() * 1.0 / llGetDayLength();
        llSetText(printTimeOfDay(timeOfDay), <1,1,0>, 1);
    }
}

Deep Notes

Search JIRA for related Issues

Signature

function integer llGetDayOffset();