Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Make a clock say the time when clicked?

Guile Yifu
Registered User
Join date: 29 Mar 2007
Posts: 9
10-01-2008 06:59
Hi I'm trying to make a clock say the time when it is clicked IE similar to the default "Hello Avatar!" script.

But, instead of saying Hello Avatar, I want it to say "The time is: (the current time in digits, PDT)." I'd also like the message to be private to whomever clicks it, so other people don't see it.

I looked around for a script myself but they were all like... for making actual clocks that rotate and stuff. Not what I want.

Hope someone can help, thanks!
Scott Savira
Not Scott Saliva
Join date: 10 Aug 2008
Posts: 357
10-01-2008 07:19
Don't have time to write an example, but....

What you probably want to do is call llGetWallClock() to get the current PDT time.

You can set all that up in a touch event and then use llInstantMessage to tell the toucher the time.
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
10-01-2008 08:15
From: Guile Yifu
Hi I'm trying to make a clock say the time when it is clicked IE similar to the default "Hello Avatar!" script.

But, instead of saying Hello Avatar, I want it to say "The time is: (the current time in digits, PDT)." I'd also like the message to be private to whomever clicks it, so other people don't see it.

I looked around for a script myself but they were all like... for making actual clocks that rotate and stuff. Not what I want.

Hope someone can help, thanks!


I don't know how robust this is but try this:

CODE


default
{
touch_start(integer total_number)
{
string sTimeStamp = llGetTimestamp();
integer iTimeIndex = llSubStringIndex(sTimeStamp, "T") + 1;
llInstantMessage(llDetectedKey(0), "The time is " + llGetSubString(sTimeStamp, iTimeIndex, iTimeIndex + 7));
}
}




EDIT - Now that I think about it again, llGetTimestamp is in GMT, not PDT, so there will have to be some adjustments to my script to change that.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses
http://slurl.com/secondlife/Wild%20Rice/38/230/51
Guile Yifu
Registered User
Join date: 29 Mar 2007
Posts: 9
10-01-2008 08:32
Perfect, thank you both. I combined your tips with a script I found in the Second Life wiki to get:

CODE


//Simple clock by Beverly Larkin to show example of how to use llGetWallClock()

integer H; //Hours
integer M; //Minutes
string AP; //AM or PM

default
{
state_entry()
{

}

touch_start(integer total_number)
{


integer T = (integer)llGetWallclock(); // Get time PST
if (T > 43200) //If it's after noon
{
T = T - 43200; //Subtract 12 hours
AP = " PM PDT."; //set to PM
H = T / 3600; //get hours
M = (T - (H * 3600)) / 60; //get minutes
if(H == 0) //if the hour is 0
{
H = 12; // make the hour 12
}
}
else
{
AP = " AM PDT."; //set to AM
H = T / 3600; //get the hour
M = (T - (H * 3600)) / 60; //get minutes
if(H == 0) //if the hour is 0
{
H = 12; // make the hour 12
}
}
if(M < 10)
{
llInstantMessage(llDetectedKey(0),"The time is " + (string)H + ":" + "0" + (string)M + AP); //if the minutes is less than 10 add the extra 0 (so it doesn't say 1:3PM) for example
}
else
{
llInstantMessage(llDetectedKey(0),"The time is " + (string)H + ":" + (string)M + AP); // otherwise just say the time
}
}
}



The end result is basically the clicked object whispering like this: "The time is 8:29 AM PDT.".
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
10-01-2008 08:43
From: Guile Yifu
Perfect, thank you both. I combined your tips with a script I found in the Second Life wiki

----edited----

The end result is basically the clicked object whispering like this: "The time is 8:29 AM PDT.".


That's great. I love when people don't just sit on their hands waiting for someone else to do everything for them.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses
http://slurl.com/secondlife/Wild%20Rice/38/230/51
Mok Rau
Registered User
Join date: 3 Jul 2007
Posts: 5
One possible solution
10-01-2008 09:32
One possible way of doing it could be:


// Mok Rau's real simple digital clock display script
//------------------------------------------------------
// Drop this script into a prim and touch it. The script
// will send a message visible only to the owner in the
// format "The time is 18:30 SLT".
// Oct/08

// Uncomment one of the two next sentences below to choose
// the display format: 24-h (23:30) 12-h or AM-PM (11:30pm)...
string sFormat = "24H"; // 24-hour format
//sformat = "AMP"; // 12-hour format with AM/PM

// Uncomment one of the two next sentences to choose between local
// simulator time or second life time
string sTimeZone = "SLT"; // Second Life Time
//sTimeZone = "LOC"; // Local time

default {
state_entry(){
llOwnerSay("Clock ready. Format "+sFormat+" "+sTimeZone);
}

touch_start(integer i){
float nTime = 0;

if (sTimeZone == "SLT";){
nTime = llGetWallclock();
}else{
nTime = llGetTimeOfDay();
}
integer iHour = (integer)(nTime / 3600);
integer iMin = (integer)(nTime / 60) % 60;
string sAmPm = "";
string sMin = (string)iMin;
if (iMin < 10){
sMin = "0" + sMin;
}
if (sFormat == "AMP";){
if (iHour >= 12){
iHour -= 12;
}
if (nTime > 43200){
sAmPm = "pm";
}else{
sAmPm = "am";
}
}
llInstantMessage(llDetectedKey(0),"The time is "+(string)iHour+":"+sMin+sAmPm+" "+sTimeZone);
}
}

Edit-- sorry to clutter. Went inworld to check the code and didn't notice the other replies...
_____________________
- My other avatar is a real hot chick.