Library: Ceera's Westminster Clock: Scripts to make a three-prim analog clock.
|
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
|
01-11-2008 15:20
This set of scripts will allow you to make a three prim clock that always displays the current SL Time (Pacific Coast USA time, the same time indicated in your client's menu bar). The clock is self-regulating, and within less than one minute of being rezzed it will set itself to the correct time and then keep accurate time. In addition to this set of three scripts, you'll need a texture for your clock face that at least indicates where 12 noon is, a texture for the minute hand (long hand), and a texture for the hour hand (short hand). You'll also probably want a texture that is 100% clear, for the sides of the hand prims. The clock face texture can be a simple square texture. I made mine with a round face bezel, and colored the corners the same as the clock face. The textures for the hands should have the pivot point for the hand at the vertical and horizontal mid-point of the texture, with the hand pointing to the top of the texture. The area below the pivot point and to either side of the hand should be transparent (IE: It's a 32-bit texture). The hand textures can be square, just like the clock face, or they can be proportioned narrower. (You could, technically, just use a texture that is opaque on the top and transparent on the bottom half, and shape the hand prim to make the hand shape. But the center of the prim's X and Y dimensions still needs to be at the center of the clock face.) For simplicity's sake, I am assuming that you are using three square textures. Rez a prim, make it the height and width that you want for your clock face, and make it the thickness in the Z-direction that you want for the thickness of the face. The prim can be a cube or a cylinder. Apply the clock face texture to the top of the prim (+Z face), and texture the other sides of the prim however you like, for the sides and back of the clock. Drag-copy that prim upward, and do it again, to make prims for the two hands. Texture them 100% transparent on all sides but the top, and place the appropriate hand texture on the top. Adjust the thickness (Z axis height) of the hands as desired. Place the three scripts below in the three prims. The main script, "Ceera's Westminster Clock Script", goes in the clock face. The other two go in the hour hand and minute hand, respectively. Edit the Z-positions of the two hands so they are close to the clock face, then link the clock together, so the clock face is the root prim. Take the clock into inventory, then rez it on the ground again. It should set to the correct time within less than a minute of being rezzed. You can now change the orientation of the clock however you like, and you can resize it as desired, from a bedside alarm clock to a huge clock for a clock tower. NOTES: This clock does not allow you to make any adjustments for time zone. It displays whatever Linden Lab is reporting as SL time (which will adjust for daylight savings time on its own). There is a bug in SL at this time that seems to limit how far away you can hear an audible sound, at least partially based on the size of the prim making the sound. A clock face that measures 0.5 M high and wide will only be audible about 25 M away. A clock face that measures 5.0 M high and wide may be audible as much as 125 M away, but the results have been inconsistent, and sometimes sound is still limited to 25 M range. Ceera's Westminster Clock Script From: someone // Ceera's Westminster Clock, with hour chimes // Based on simple clock by Beverly Larkin // Uses two linked message scripts in the hour hand and minute hand. // Always displays current SL time (Pacific Coast Time) integer H; //Hours integer M; //Minutes string chimeA = "95a691d0-21c0-21c2-5918-e18ed7e05b2e"; // First 10 sec of top-of-hour chimes string chimeB = "f5ba3a09-5fa2-d4ac-92bc-4d0000a2e786"; // Second 10 sec of top-of-hour chimes string chimeBong = "d87217bc-cb47-7d85-c2ea-b0e3d2e40a72"; // a two-second single bong getTime() { integer T = (integer)llGetWallclock(); // Get time PST if (T > 43200) //If it's after noon { T = T - 43200; //Subtract 12 hours 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 { 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 } } } chimeCheck() { if(M == 59) // preload chime sounds { llPreloadSound( chimeA ); // First 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeB ); // Second 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeBong ); // a two-second single bong llSleep(2); } if(M == 0) // Time to strike the hour! { llSetSoundQueueing(FALSE); // Don't wait until sound is done before playing next sound // Play the top of the hour bells llPlaySound(chimeA,1.0); llSleep(10); llPlaySound(chimeB,1.0); llSleep(10); // Chime the hour integer i = 0; for (; i < H; ++i) // Loop for the number of hours { llPlaySound(chimeBong,1.0); llSleep(2.0); } } } default { on_rez(integer start_param) { // Restarts the script every time the object is rezzed llSetTimerEvent(60); // Activate the timer to get time every one minute getTime(); llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, H, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } timer() { getTime(); llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, H, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } } Hour Hand From: someone //Script for hour hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "hour"  { float degrees=(360-30*number); rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>  ; llSetLocalRot(handPos); } } } Minute Hand From: someone // Script for minute hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "minutes"  { float degrees=(360-6*number); rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>  ; llSetLocalRot(handPos); } } }
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
Library bump
01-21-2008 14:18
_____________________
i've got nothing. 
|
Ivanova Shostakovich
Fire Resistant
Join date: 1 Oct 2007
Posts: 98
|
Modified for proportional hour hand movement
03-04-2008 14:45
This script was a great learning opportunity for me. I created a clock and realized that I wanted the hour hand to move proportionally. I created two variables, probably one more than I needed to; a float to carry high resolution data to the hour hand, and an integer into which to multiply that float for retaining its resolution through the llMessageLinked. Providing proportional hour hand movement was the only modification I made. Here is the Clock script: From: someone Modified from OP, // Ceera's Westminster Clock, with hour chimes // Based on simple clock by Beverly Larkin // Modified slightly by Ivanonva Shostakovich to provide proportional hour hand movement // Uses two linked message scripts in the hour hand and minute hand. // Always displays current SL time (Pacific Coast Time) integer H; //Hours integer M; //Minutes float HF; //For giving the hour hand its angle information - I.S. integer HS; //For passing HF through messagelinked - I.S. string chimeA = "95a691d0-21c0-21c2-5918-e18ed7e05b2e"; // First 10 sec of top-of-hour chimes string chimeB = "f5ba3a09-5fa2-d4ac-92bc-4d0000a2e786"; // Second 10 sec of top-of-hour chimes string chimeBong = "d87217bc-cb47-7d85-c2ea-b0e3d2e40a72"; // a two-second single bong getTime() { integer T = (integer)llGetWallclock(); // Get time PST if (T > 43200) //If it's after noon { T = T - 43200; //Subtract 12 hours H = T / 3600; //get hours HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } else { H = T / 3600; //get the hour HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } } chimeCheck() { if(M == 59) // preload chime sounds { llPreloadSound( chimeA ); // First 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeB ); // Second 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeBong ); // a two-second single bong llSleep(2); }
if(M == 0) // Time to strike the hour! { llSetSoundQueueing(FALSE); // Don't wait until sound is done before playing next sound // Play the top of the hour bells llPlaySound(chimeA,1.0); llSleep(10); llPlaySound(chimeB,1.0); llSleep(10); // Chime the hour integer i = 0; for (; i < H; ++i) // Loop for the number of hours { llPlaySound(chimeBong,1.0); llSleep(2.0); } } } default { on_rez(integer start_param) { // Restarts the script every time the object is rezzed llSetTimerEvent(60); // Activate the timer to get time every one minute getTime(); HS = (integer) HF * 10000; llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } timer() { getTime(); HF = HF * 10000; //Preserves the resolution of HF for integer conversion - I.S. HS = (integer) HF; //Converts HF to integer HS for sending through llMessageLinked - I.S. llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } }
Here is the hour hand script: Modified from OP, From: someone //Script for hour hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "hour") { float degrees=((360-30*number) / 10000); //Extracts accurate hour hand angle through division - I.S. rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>); llSetLocalRot(handPos); } } }
Here is the minute hand script: Not modified from OP, From: someone // Script for minute hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "minutes") { float degrees=(360-6*number); rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>); llSetLocalRot(handPos); } } }
|
Sparkin Nightfire
Registered User
Join date: 10 Jan 2008
Posts: 2
|
Havoc 4
04-27-2008 05:24
Hello, Has anyone tested this on Havoc 4? im having many issues and jsut cant get it to run right  thanks for any help anyone may have... Sparkin
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
Clock hands and face for the library clock
04-27-2008 22:55
From: Sparkin Nightfire Hello, Has anyone tested this on Havoc 4? im having many issues and jsut cant get it to run right  thanks for any help anyone may have... Sparkin I doubt Havok 4 would have anything to do with your problems, as there's nothing physical about the objects... Also, since clocks are my biz, I thought I'd contribute to this library addition, here's some free clock hands and a face that everyone is free to use. Hour hand : f5fa3b2d-9dcf-7606-c83c-f6babeadfd53 Min hand : 9b11f634-750d-672f-e929-6978ea726247 clock face : 7433287a-dbb7-6f00-b7e5-e35ed9be4b18 They're simple, but then again... they're freebies... 
|
Partington Gould
Registered User
Join date: 15 Sep 2005
Posts: 94
|
04-28-2008 07:18
I had a Clock on a building operating pre-Havok 4 and through the update to Havok.
It still works fine, I had no need to touch it, no reset was required.
_____________________
PG - Permanently Confused and prone to Wandering
|
Billyboy Cortes
Registered User
Join date: 2 Jun 2007
Posts: 3
|
How to set the prims up?
05-05-2008 10:38
This is not really the right way to put my question, but, I'll try to explain. lol As soon as I link the 3 prims together, the hour prim and the minute prim get in an ackward position. So is there any way to rotate the prims so that the face where the hands are on, keep on the top and rotate in a clockwise movement? Or do the textures for the hands have to be on a specific side of the prim? I was a bit embrrased to ask this, but I have been trying to get it right, and it seems I'm just a dumbass in linking things and as I only started 2 weeks ago with the scripting languages, I'm lost. 
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
05-05-2008 19:30
From: Billyboy Cortes This is not really the right way to put my question, but, I'll try to explain. lol As soon as I link the 3 prims together, the hour prim and the minute prim get in an ackward position. So is there any way to rotate the prims so that the face where the hands are on, keep on the top and rotate in a clockwise movement? Or do the textures for the hands have to be on a specific side of the prim? I was a bit embrrased to ask this, but I have been trying to get it right, and it seems I'm just a dumbass in linking things and as I only started 2 weeks ago with the scripting languages, I'm lost.  Yeah, I had that issue to, which is just one of the reasons I abandoned prim hands. Try rotating everything to <0,0,0> before linking, that should help a bit. Personally, I just use cylinders, and rotate the texture on the flat of the cylinder. That way, you dont have to concern yourself with local and world rotations. the problem is the 'weird' rotations are the hands pointing into the world (not local) co-ordinates.
|
Crunch Underwood
Mr. Grown up, Go away sir
Join date: 25 Sep 2007
Posts: 624
|
05-05-2008 21:23
the clocktower in Laputa uses this script, no problems at all as far as i can tell
-Crunch
_____________________
---------------------------------------------- So your final Nimbus Score is 8.15, a quite remarkable achievement for a biped. Congratulations Crunch, you should be very proud. 
|
Partington Gould
Registered User
Join date: 15 Sep 2005
Posts: 94
|
05-06-2008 07:09
I use this at Jade's Jazz Island, it's actually rotated 45-degrees to the land and works fine, the root is a cylinder, the Hands are all box prims.
I made the clock a few months ago so forgot the specifics, but basically followed the instructions. I used shift-drag to copy all the prims I didn't rotate anything.
Once the clock was running, then I rotated 45-degrees to line-up with the wall.
Thanks
_____________________
PG - Permanently Confused and prone to Wandering
|
Billyboy Cortes
Registered User
Join date: 2 Jun 2007
Posts: 3
|
Thanks everyone
05-06-2008 12:26
Wow. Thanks everyone for the answers, ...I'll sure give it a new try, but this time with cylinders. I was getting mad at myself, lol, and started swearing at some time, but I'll gather myself together and give it a new shot. I'll let you know if it works for me. 
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-06-2008 11:03
very nice, i tried using a second hand as well, but, since it makes it rotate every second, it's almost like a constant rotation which is quite laggy also, if you do want to adjust the time zone, you can add/subtract 3600 seconds for each hour difference in the GetWallClock line, IE: integer T = (integer)llGetWallclock()+7200; (+7200 is 2 hours ahead)
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-06-2008 11:25
here's my version with the time zone adjustment, all you have to do is put in how many hours behind/ahead you are and it does the math for you. the line to write that in is: integer LocalT = 2; (just change the 2 to your hour difference) IE "-2" is 2 hours behind edit: also changed the on_rez state, to state entry, and then added an on_rez state to reset the script. (no need to keep re-rezzing the clock if you're adjusting it) From: someone // Ceera's Westminster Clock, with hour chimes // Based on simple clock by Beverly Larkin // Modified slightly by Ivanonva Shostakovich to provide proportional hour hand movement //Modified Slightly by Ruthven Willenov to add Time Zone Adjustment // Uses two linked message scripts in the hour hand and minute hand. integer H; //Hours integer M; //Minutes float HF; //For giving the hour hand its angle information - I.S. integer HS; //For passing HF through messagelinked - I.S. string chimeA = "95a691d0-21c0-21c2-5918-e18ed7e05b2e"; // First 10 sec of top-of-hour chimes string chimeB = "f5ba3a09-5fa2-d4ac-92bc-4d0000a2e786"; // Second 10 sec of top-of-hour chimes string chimeBong = "d87217bc-cb47-7d85-c2ea-b0e3d2e40a72"; // a two-second single bong getTime() { integer LocalT = -2; //how many hours ahead/behind PST? integer diff = LocalT*3600;//how many seconds in the hour difference? integer T = (integer)llGetWallclock()+diff; // Get time PST if (T > 43200) //If it's after noon { T = T - 43200; //Subtract 12 hours H = T / 3600; //get hours HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } else { H = T / 3600; //get the hour HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } } chimeCheck() { if(M == 59) // preload chime sounds { llPreloadSound( chimeA ); // First 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeB ); // Second 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeBong ); // a two-second single bong llSleep(2); } if(M == 0) // Time to strike the hour! { llSetSoundQueueing(FALSE); // Don't wait until sound is done before playing next sound // Play the top of the hour bells llPlaySound(chimeA,1.0); llSleep(10); llPlaySound(chimeB,1.0); llSleep(10); // Chime the hour integer i = 0; for (; i < H; ++i) // Loop for the number of hours { llPlaySound(chimeBong,1.0); llSleep(2.0); } } } default { on_rez(integer start_param) { llResetScript(); } state_entry() { // Restarts the script every time the object is rezzed llSetTimerEvent(60); // Activate the timer to get time every one minute getTime(); HS = (integer) HF * 10000; llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } timer() { getTime(); HF = HF * 10000; //Preserves the resolution of HF for integer conversion - I.S. HS = (integer) HF; //Converts HF to integer HS for sending through llMessageLinked - I.S. llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } }
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
08-06-2008 14:08
Thanks, Ruthven; wouldn't, though, llGetGMTclock() be a better idea than llGetWallclock() for doing time zone adjustment, since, as GMT is, in the words of the script wiki, "an absolute and international measure of time that does not change throughout the year", you only have to change the scripts when your own local daylight savings start and stop and don't need to worry about what's happening in California, too?
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-06-2008 15:12
From: Innula Zenovka Thanks, Ruthven; wouldn't, though, llGetGMTclock() be a better idea than llGetWallclock() for doing time zone adjustment, since, as GMT is, in the words of the script wiki, "an absolute and international measure of time that does not change throughout the year", you only have to change the scripts when your own local daylight savings start and stop and don't need to worry about what's happening in California, too? sure, that would work too, but as i spend alot of time in sl, i pay more attention to it's time versus my time. to each his own. if you prefer that method then ok i am working on a dialog script to work with this one actually, so that users can choose the time zone instead of having to edit the script
|
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
|
08-07-2008 09:35
From: Ruthven Willenov i am working on a dialog script to work with this one actually, so that users can choose the time zone instead of having to edit the script In the clocks I have made I use GMT by default and allow the user to put a time zone and offset in the description field. If the user wanted SL time the description reads PDT if they are east coast it reads PDT+4 (just guessing) in my case GMT+2 as we are 2 hours ahead and dont have Daylight saving at all.
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-07-2008 17:49
From: Very Keynes In the clocks I have made I use GMT by default and allow the user to put a time zone and offset in the description field. If the user wanted SL time the description reads PDT if they are east coast it reads PDT+4 (just guessing) in my case GMT+2 as we are 2 hours ahead and dont have Daylight saving at all. hehe, i did go that route instead, but only with the offset. i couldn't figure out how to make it receive the link message from the menu script to change the offset. i'm assuming you used some sort of substring command to use GMT/ PDT in the description field? never worked with substrings before, so no clue how it would work i wanted the menu script so that the time would change immediately without having to manually reset the script. i did try using the notecard method, but it wasn't working either. also a problem i've been having while testing the clock: i'm central time, which is GMT-6, but for it to display the correct time i've have to put -5 (using the descripting method) -6 works fine when i hard code it
|
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
|
08-08-2008 03:44
From: Ruthven Willenov i'm assuming you used some sort of substring command to use GMT/ PDT in the description field? never worked with substrings before, so no clue how it would work Try this version, I have put in the substring functions for you. It will default to PST if the description is blank or invalid valid descriptions (not case sensative) are: GMT-6 PST+2 gmt2 or even just gmt // Ceera's Westminster Clock, with hour chimes // Based on simple clock by Beverly Larkin // Modified slightly by Ivanonva Shostakovich to provide proportional hour hand movement // Modified Slightly by Ruthven Willenov to add Time Zone Adjustment // Modified by Very Keynes to fetch Time zone from Description Field // Uses two linked message scripts in the hour hand and minute hand. integer H; //Hours integer M; //Minutes float HF; //For giving the hour hand its angle information - I.S. integer HS; //For passing HF through messagelinked - I.S. string chimeA = "95a691d0-21c0-21c2-5918-e18ed7e05b2e"; // First 10 sec of top-of-hour chimes string chimeB = "f5ba3a09-5fa2-d4ac-92bc-4d0000a2e786"; // Second 10 sec of top-of-hour chimes string chimeBong = "d87217bc-cb47-7d85-c2ea-b0e3d2e40a72"; // a two-second single bong getTime() { string TimeZone = llGetObjectDesc();//format examples GMT-6 or PST+4 integer LocalT = (integer)llGetSubString(TimeZone,3,-1); //how many hours ahead/behind? integer diff = LocalT*3600;//how many seconds in the hour difference? integer T = (integer)llGetWallclock()+diff; // Get time PST if("GMT" == llToUpper(llGetSubString(TimeZone,0,2))) T = (integer)llGetGMTclock()+diff; // Get time GMT if (T > 43200) //If it's after noon { T = T - 43200; //Subtract 12 hours H = T / 3600; //get hours HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } else { H = T / 3600; //get the hour HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } } chimeCheck() { if(M == 59) // preload chime sounds { llPreloadSound( chimeA ); // First 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeB ); // Second 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeBong ); // a two-second single bong llSleep(2); } if(M == 0) // Time to strike the hour! { llSetSoundQueueing(FALSE); // Don't wait until sound is done before playing next sound // Play the top of the hour bells llPlaySound(chimeA,1.0); llSleep(10); llPlaySound(chimeB,1.0); llSleep(10); // Chime the hour integer i = 0; for (; i < H; ++i) // Loop for the number of hours { llPlaySound(chimeBong,1.0); llSleep(2.0); } } } default { on_rez(integer start_param) { llResetScript(); } state_entry() { // Restarts the script every time the object is rezzed llSetTimerEvent(60); // Activate the timer to get time every one minute getTime(); HS = (integer) HF * 10000; llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } timer() { getTime(); HF = HF * 10000; //Preserves the resolution of HF for integer conversion - I.S. HS = (integer) HF; //Converts HF to integer HS for sending through llMessageLinked - I.S. llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); chimeCheck(); // Comment this out to silence the chimes } }
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-08-2008 09:08
awesome, thanks, i'll try that as soon as i get home and go in world. and i will read up on substrings to try to understand how it works
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
08-08-2008 18:34
question, have you noticed when you reset the script, the hour hand resets itself directly on the hour? why does it do that when the state entry is basically just calling the same thing the timer does? not really an issue, i'm just a little OCD lol
|
Harmony Deschanel
Registered User
Join date: 4 Jan 2007
Posts: 32
|
Added second hand movement to the clock
11-01-2008 16:36
I added a second hand that rotates using llTargetOmega, and corrects itself along with the linked message part of the script in case it lags or drifts. One thing I noticed and maybe some of the scripting gurus can explain this... The second hand only corrects it's rotation if the timer is NOT set to 60 seconds ... I set it to 59, 55, 47, and it would correct it's position. Anyone know why? EDIT: I should have said "The second hand only corrects it's position if...." not "rotation" This increases the prim count to 4 since you need to add one more prim, like it was explained to do for the minute and second hand, for the second hand. Clock script (modifed from last post it was in by Very Keynes #1  From: someone // Ceera's Westminster Clock, with hour chimes // Based on simple clock by Beverly Larkin // Modified slightly by Ivanonva Shostakovich to provide proportional hour hand movement // Modified Slightly by Ruthven Willenov to add Time Zone Adjustment // Modified by Very Keynes to fetch Time zone from Description Field // Modified by Harmony Deschanel to include a second hand. // Uses two linked message scripts in the hour hand, minute, and second hand. (HD) integer H; //Hours integer M; //Minutes integer S; //Seconds (HD) float HF; //For giving the hour hand its angle information - I.S. integer HS; //For passing HF through messagelinked - I.S. string chimeA = "95a691d0-21c0-21c2-5918-e18ed7e05b2e"; // First 10 sec of top-of-hour chimes string chimeB = "f5ba3a09-5fa2-d4ac-92bc-4d0000a2e786"; // Second 10 sec of top-of-hour chimes string chimeBong = "d87217bc-cb47-7d85-c2ea-b0e3d2e40a72"; // a two-second single bong
getTime() { string TimeZone = llGetObjectDesc();//format examples GMT-6 or PST+4 integer LocalT = (integer)llGetSubString(TimeZone,3,-1); //how many hours ahead/behind? integer diff = LocalT*3600;//how many seconds in the hour difference? integer T = (integer)llGetWallclock()+diff; // Get time PST if("GMT" == llToUpper(llGetSubString(TimeZone,0,2))) T = (integer)llGetGMTclock()+diff; // Get time GMT if (T > 43200) //If it's after noon { T = T - 43200; //Subtract 12 hours H = T / 3600; //get hours HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes S = T - ((H * 3600) + (M * 60)); // get seconds (HD) if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } else { H = T / 3600; //get the hour HF = (float) T / 3600; //Gets HF - I.S. M = (T - (H * 3600)) / 60; //get minutes S = T - ((H * 3600) + (M * 60)); // get seconds (HD) if(H == 0) //if the hour is 0 { H = 12; // make the hour 12 } } }
chimeCheck() { if(M == 59) // preload chime sounds { llPreloadSound( chimeA ); // First 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeB ); // Second 10 sec of top-of-hour chimes llSleep(10); llPreloadSound( chimeBong ); // a two-second single bong llSleep(2); } if(M == 0) // Time to strike the hour! { llSetSoundQueueing(FALSE); // Don't wait until sound is done before playing next sound // Play the top of the hour bells llPlaySound(chimeA,1.0); llSleep(10); llPlaySound(chimeB,1.0); llSleep(10); // Chime the hour integer i = 0; for (; i < H; ++i) // Loop for the number of hours { llPlaySound(chimeBong,1.0); llSleep(2.0); } } }
default { on_rez(integer start_param) { llResetScript(); }
state_entry() { // Restarts the script every time the object is rezzed llSetTimerEvent(59); // Activate the timer to get time every one minute // Note from HD: If you use 60 as the time in the timer event // the second hand won't correct it's position. I have no idea why. getTime(); HS = (integer) HF * 10000; llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); llMessageLinked(LINK_SET, S, "seconds", NULL_KEY); // (HD) chimeCheck(); // Comment this out to silence the chimes }
timer() { getTime(); HF = HF * 10000; //Preserves the resolution of HF for integer conversion - I.S. HS = (integer) HF; //Converts HF to integer HS for sending through llMessageLinked - I.S. llMessageLinked(LINK_SET, M, "minutes", NULL_KEY); llMessageLinked(LINK_SET, HS, "hour", NULL_KEY); llMessageLinked(LINK_SET, S, "seconds", NULL_KEY); // (HD) chimeCheck(); // Comment this out to silence the chimes } }
Hour Hand Script (no change from last post it was given in by Ivanova Shostakovich #3) From: someone //Script for hour hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "hour"  { float degrees=((360-30*number) / 10000); //Extracts accurate hour hand angle through division - I.S. rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>  ; llSetLocalRot(handPos); } } } Minute Hand Script (Not modified from OP #1) From: someone // Script for minute hand default { link_message(integer sender_number,integer number,string message,key id) { if(message == "minutes"  { float degrees=(360-6*number); rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>  ; llSetLocalRot(handPos); } } } Second Hand Script (New) From: someone // Script for second hand added by Harmony Deschanel default { state_entry() { llTargetOmega(<0,0,-1>,PI/30,1); } link_message(integer sender_number,integer number,string message,key id) { if(message == "seconds"  { float degrees=-6*number; rotation handPos=llEuler2Rot(<0,0,degrees*DEG_TO_RAD>  ; llSetLocalRot(handPos); } } }
|
Thickbrick Sleaford
Baffled
Join date: 28 Dec 2006
Posts: 26
|
11-01-2008 20:26
From: Harmony Deschanel The second hand only corrects it's rotation if the timer is NOT set to 60 seconds ... I set it to 59, 55, 47, and it would correct it's position. Anyone know why? I think that is because the sim only send an update to the viewer if the rotation changes by more than 0.1 radians (?). As far as the sim is concerned, llTargetOmega isn't rotating the prim, and it is resting at the last rotation you set it to. If you always set the same rotation (every 60 seconds,) it thinks the viewer doesn't need to be informed about it.
|
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
|
11-02-2008 06:41
In my own clock script project I use three scripts in the three moving objects: the hour hand, the minute hand and the second hand. It works great. Note that I do use box prims for clock hands with one half transparent and the other half the hand graphic. This is my second hand script. I've had this running on my land for a long time without issue. It's always worked flawlessly. Once in awhile a lag spike will cause the tick to have to catch up, but it does work exactly like a real clock and I find the ticking to be soothing while I'm building or working on scripts. From: someone default { state_entry() { llSetTimerEvent(1); } timer() { float second = llGetWallclock(); llPlaySound("single tick",1.0); rotation hand_rot = llEuler2Rot(<0, 6 * second * DEG_TO_RAD, 0>  ; llSetLocalRot(hand_rot); } }
|
Harmony Deschanel
Registered User
Join date: 4 Jan 2007
Posts: 32
|
11-02-2008 08:26
From: Thickbrick Sleaford I think that is because the sim only send an update to the viewer if the rotation changes by more than 0.1 radians (?). As far as the sim is concerned, llTargetOmega isn't rotating the prim, and it is resting at the last rotation you set it to. If you always set the same rotation (every 60 seconds,) it thinks the viewer doesn't need to be informed about it. Thickbrick, sorry I should have said: From: someone The second hand only corrects it's "position" if the timer is NOT set to 60 seconds ... I set it to 59, 55, 47, and it would correct it's position. Anyone know why? I don't understand what you mean when you say "llTargetOmega isn't rotating the prim" The second hand moves with smooth movement, and the timer event's linkedmessage is in there to correct the position of it in case of lag, or if you edit it and stop the rotation. I'm more a copy/paste/trial and error scripter hehe .. I don't understand alot of what's going on most of the time in scripts.
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
11-02-2008 08:49
target omega is a client side effect. so while you see the second hand on 15, someone else could see it on 45 at the same time. what i meant about being ocd was about it resetting when the timezone offset is changed. and also, when the script is reset, the hour hand is set directly on the hour, but it fixes itself on the next minute. not sure why since it's calling the same function in the state entry and the timer.
i decided not to worry about the second hand because who's really gonna watch a clock that closely? on the other hand, if someone was looking for a stopwatch, i would just use a rl one lol since stopping and starting one in sl would ultimately be thrown off by lag
yingzi, i would advise not triggering a sound every second, you could instead simply loop the sound with llLoopSound,and it would only need to be called once. the sound even becomes a prim property as particles do, so you could remove the script from the prim after starting it. (the sound will play as long it's not copied with shift drag, same with particles)
|