Difference between revisions of "TimeAPI Clock Script"
m (<lsl> tag to <source>) |
Lou Netizen (talk | contribs) m |
||
Line 1: | Line 1: | ||
{{LSL Header}} | {{LSL Header}} | ||
This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time. | This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time. | ||
[Note: timeapi.org seems to have shut down in 2017. However, the principles of this script still illustrate simple HTTP GET usage from LSL.] | |||
== Script == | == Script == |
Revision as of 11:32, 20 June 2018
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time. [Note: timeapi.org seems to have shut down in 2017. However, the principles of this script still illustrate simple HTTP GET usage from LSL.]
Script
key reqKey;
default
{
state_entry(){
llSetTimerEvent(1);
}
http_response(key req_id, integer status, list metadata, string body)
{
if (req_id == reqKey)
{
if(status == 200) {
llSetText(body,<1,1,1>,1.0);
} else {
llSetText("ERROR",<1,0,0>,1.0);
}
}
}
timer()
{
reqKey = llHTTPRequest("http://www.timeapi.org/utc/now?format=%25H:%25M:%25S", [HTTP_METHOD,"GET"],"");
}
}
Since llGetWallClock() returns Pacific time and llGetGMTClock() returns UTC and that counts seconds since midnight, this script shows time in UTC, Eastern Time, Central Time, Mountain Time, Pacific Time, Alaska time, Hawaii time, CET, EET or Moscow time.
You can customize the display of the clock by editing the format. (This requires understanding for Ruby coding) For reference, please see http://apidock.com/ruby/Time/strftime
For infomation on TimeAPI, please see http://www.timeapi.org/
The HTTP clock script is open-sourced and it is in the public domain. You can contribute to it and use it in your projects.