These forums are CLOSED. Please visit the new forums HERE
Clock script? |
|
Layla Shriner
Registered User
Join date: 23 Oct 2005
Posts: 18
|
06-16-2006 00:12
I'm interested in crafting a series of clocks, and have read somewhere that there exist scripts to make a clock or watch tell the actual time. Could someone please direct me to where I may find one of these? Thank you in advance.
|
Sergeant Benton
European Perspective
![]() Join date: 30 May 2005
Posts: 46
|
ClockWorX does them
06-16-2006 00:38
Come on over, or IM me in SL and I'll send you a catalogue.
|
Sean Martin
Yesnomaybe.
![]() Join date: 13 Sep 2005
Posts: 584
|
06-16-2006 21:29
I got the base of this code from somewhere on the forums I believe. And I can't remember who it was otherwise I'd credit them. But it's been edited a bit from the origonal to adapt correctly in a few clocks I made. I just tried to put it back to how it was so it should be about right.
In any case, I'm not sure why clock scripts are so closly guarded in SL. It's just math that has existed outside of secondlife for centuries. A google search will get you the basic formula. The only thing you need is to adapt it to rotating a texture. But anyway here's what I've been using: Minute Hand: CODE
Hour Hand: CODE
Each hand has its own prim, texture, and script. For the hand textures, they need to be alpha if you want the clock face prim to show behind it. Also each hand's texture needs to point up when you make it. As if it were pointing to 12. The face of the clock is usually a 3rd prim behind the hand prims. You could do second hands by working off the minute hand. But the timer needs to be called every second and that might add to unnecessary lag. _____________________
![]() |
Layla Shriner
Registered User
Join date: 23 Oct 2005
Posts: 18
|
Thanks.
06-16-2006 22:30
Thanks to both of you, that's great. Now, let's see if I can find a cuckoo script...
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-17-2006 08:11
Cool thanks for this script.
Been working on a realistic pocket watch. I was wondering is there was a consistant way to so a second hand? I was thinking about a rotation that just happens to take one minute to get around the clock. Anyone have a better way of going about it. |
Foolish Frost
Grand Technomancer
![]() Join date: 7 Mar 2005
Posts: 1,433
|
06-17-2006 08:58
Cool thanks for this script. Been working on a realistic pocket watch. I was wondering is there was a consistant way to so a second hand? I was thinking about a rotation that just happens to take one minute to get around the clock. Anyone have a better way of going about it. Nope, using the animated texture command to make a texture that rotates at once per minute is an EXCELLENT idea! It may not be prefect, but it will reduce lag! Just have every minute it reset the rotation script again! That way it will stay in synch in the long term as well. |
Colina Pomeray
Registered User
Join date: 2 Jun 2005
Posts: 7
|
Second hands??
11-22-2006 11:26
You could do second hands by working off the minute hand. But the timer needs to be called every second and that might add to unnecessary lag. umm... Is it possible to have the second hands code as well? Thanks in advance ![]() |
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-22-2006 11:33
umm... Is it possible to have the second hands code as well? Take the minute hand script. Replace this line: minute = (MainClock / 60) - (llFloor(MainClock / 60 / 60) * 60); with minute = MainClock % 60; save, put it in the second hand. note, this will update the hand once every 10 seconds. To get it update more often change llSetTimerEvent() frequency in the script to 1 or so from current 10, or something. |
Colina Pomeray
Registered User
Join date: 2 Jun 2005
Posts: 7
|
Thanks!
11-22-2006 11:40
Thank you so much, that was fast
![]() Col |
Meade Paravane
Hedgehog
![]() Join date: 21 Nov 2006
Posts: 4,845
|
11-22-2006 11:45
As a suggestion, you might want to schedule these timers less often - updating the hour hand every 10 seconds kinda seems like overkill. Unless it's a big clock where you can actually see 5-6 differences between notches on the dial, 10 seconds is also a little much for the minute hand.
You can also squeeze a little better performance by comparing the last rotation against the new rotation and only calling llRotateTexture if the difference is greater than some threshold. |
Colina Pomeray
Registered User
Join date: 2 Jun 2005
Posts: 7
|
Error...
11-22-2006 11:48
Take the minute hand script. Replace this line: minute = (MainClock / 60) - (llFloor(MainClock / 60 / 60) * 60); with minute = MainClock % 60; save, put it in the second hand. note, this will update the hand once every 10 seconds. To get it update more often change llSetTimerEvent() frequency in the script to 1 or so from current 10, or something. Well, I'm sorry to say, but I got an error msg on that when I tried it ![]() |
Jopsy Pendragon
Perpetual Outsider
![]() Join date: 15 Jan 2004
Posts: 1,906
|
11-22-2006 12:18
Well, I'm sorry to say, but I got an error msg on that when I tried it ![]() Wouldn't " ![]() I've put a clock in The Particle Laboratory that I made a while back, much like the one described here (but without the second-hand reset at the top of each minute.) In addition to seconds, minutes and hours... it also has "night phases" which still confound me, honestly. I use llGetWallclock() to fgiure out when midnight was and align my "night phase" texture... but it's obviously befuddled if the sim has rebooted since midnight. It would probably be more useful to base it upon the sun position, since that's the intent. Has anyone tried calculating when sunrise, sunset, noon and midnight would be with regards to the sim's sun? _____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources.
Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas. - Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store! |
Colina Pomeray
Registered User
Join date: 2 Jun 2005
Posts: 7
|
Thanks Jopsy
11-22-2006 12:27
minute = ((integer)MainClock) % 60; Thanks, that worked ![]() Col |
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-22-2006 12:37
Wouldn't " ![]() Doh, sorry about it. Didn't occur to me someone would use floats to store the initial results so i didn't look at variable definitions ^^;; |
Klear Moonlight
Registered User
Join date: 4 Sep 2005
Posts: 5
|
clock scripts
03-15-2007 11:40
clock hour hand, and clock minute hand script work great, but seems that seconds hand script doesn't seem to be as smooth as some i have seen, and not easy setting different times on clock is there a way to get seconds hand to move with seconds like other clocks and a easy way of setting hr with these?
|
Jopsy Pendragon
Perpetual Outsider
![]() Join date: 15 Jan 2004
Posts: 1,906
|
03-15-2007 13:54
For the second hand I tend to use:
llSetTextureAnim(ANIM_ON | LOOP | ROTATE, ALL_SIDES, 1,1, 0.0, TWO_PI, 60.0); Or something similar... (can't test or get in world from where I am now or I'd get you the exact line) If I remember right I have it re-issue it once a minute so that the second hand is synchronized. (otherwise the secondhand starts rotating as soon as someone is watching it). ![]() |
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
|
Second hand
08-28-2007 10:53
Here it is. Tested it and it works like a charm
![]() float seconds; float secondsRotate; float mainClock; default { state_entry() { llSetTimerEvent(1); } timer() { mainClock = llGetWallclock(); seconds = mainClock - (llFloor((mainClock / 60) - (llFloor(mainClock / 60 / 60) * 60)) * 60); secondsRotate = (2 * -PI * (seconds / 60)); llRotateTexture(secondsRotate, ALL_SIDES); } } |