Difference between revisions of "LlGetRegionDayLength"
Jump to navigation
Jump to search
(Created page with "{{LSL_Function |func=llGetRegionDayLength|return_type=integer |func_desc=Return the number of seconds in the day cycle applied to the current region. llGetDayLength return...") |
Tapple Gao (talk | contribs) (add an example script displaying the current region time) |
||
Line 2: | Line 2: | ||
|func=llGetRegionDayLength|return_type=integer | |func=llGetRegionDayLength|return_type=integer | ||
|func_desc=Return the number of seconds in the day cycle applied to the current region. [[llGetDayLength]] returns the number of seconds for the current parcel, [[llGetRegionDayLength]] is the number of seconds in the day cycle applied to the entire region. | |func_desc=Return the number of seconds in the day cycle applied to the current region. [[llGetDayLength]] returns the number of seconds for the current parcel, [[llGetRegionDayLength]] is the number of seconds in the day cycle applied to the entire region. | ||
|examples= | |||
<source lang="lsl2"> | |||
// print the apparent time of day as HH:MM (%), just like the environment window in the 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() + llGetRegionDayOffset()) % llGetRegionDayLength() * 1.0 / llGetRegionDayLength(); | |||
llSetText(printTimeOfDay(timeOfDay), <1,1,0>, 1); | |||
} | |||
} | |||
</source> | |||
|also_functions= | |also_functions= |
Revision as of 21:28, 13 May 2020
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: integer llGetRegionDayLength( );
Return the number of seconds in the day cycle applied to the current region. llGetDayLength returns the number of seconds for the current parcel, llGetRegionDayLength is the number of seconds in the day cycle applied to the entire region.
Returns an integer
Caveats
Examples
// print the apparent time of day as HH:MM (%), just like the environment window in the 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() + llGetRegionDayOffset()) % llGetRegionDayLength() * 1.0 / llGetRegionDayLength();
llSetText(printTimeOfDay(timeOfDay), <1,1,0>, 1);
}
}