Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Clock Script Help

Barnesworth Anubis
Is about to cry!
Join date: 21 Jun 2004
Posts: 921
02-18-2005 17:21
Hello!

I've been trying to make a clock that works (in acordance with the SL [PST] time), errm im bad with terminology but i want a clock that the hands rotate, i tried usuing a standrad rotation script and actually have the arms moving - but I cant get the speed right. Does anyone have a script I could borrrow that already has this timed out? or know of a better way make a clock like this? Im completely ignorant when it comes to scripting - at best i can just fiddle with the numbers a little lol.

Or am I attempting the impossible? lol

Thanks in advance!
_____________________
Bright Center of the Universe,
Barnesworth Anubis

www.barnesworthanubis.com

Alan Palmerstone
Payment Info Used
Join date: 4 Jun 2004
Posts: 659
02-18-2005 17:46
FWIW, I have an analog clock made by Damanios Thetan (Glazz Clock from the collection damani). It even has a working second hand. Maybe he can point you in the right direction.

Sinatra Cartier also has a real nice one at Club Sinatra.
_____________________
Visit Parrot Island - relax on the beach, snuggle at the waterfall, ride the jetskis, make a movie and buy a pool!
Moleculor Satyr
Fireflies!
Join date: 5 Jan 2004
Posts: 2,650
02-19-2005 05:02
Instead of trying to get the right "speed" (as you will NEVER be able to get the hands to the right speed, as the speed fluctuates with the load on the sim), instead call a timer() event every few seconds (I'd avoid using a second hand, so every five seconds or so should do) that checks the actual time, and positions the hands accordingly.

BTW, if you call llSetTimedEvent(0) and then call it again with 5 when the time -does- actually change, you're probably guaranteed to have your hands change at the proper times, no matter what, since the five second mark should coincide with a change of the hands.
_____________________
</sarcasm>
gene Poole
"Foolish humans!"
Join date: 16 Jun 2004
Posts: 324
02-20-2005 19:04
Instead of trying to "time" things, just make the prims or textures rotate to absolute co-ordinates/angles according to the time at the instance you update them.

For instance, have a timer event firing once a minute, and in the timer handler, you call llGetTimeOfDay, and set the rotation of the minute hand according to the minute value (some simple math -- division, modulo, whatever, is required).

-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
Haha, everything above this line was my original reply. I had this browser tab open from yesterday, and neglected to see if someone else had already replied. Because it's so similar to Mol's post, I'm leaving it for entertainment value (mostly my own).
FuRaz Chung
2Stylez Urban Wear
Join date: 25 Mar 2004
Posts: 27
02-27-2005 03:52
Hey Barnesworth,

I made a script that rotates the hands of my watches. The reason why you're not getting the answers you want is that people don't want you to know how to make those cool watches! Hehehe! I promise you that, when I can log in, I'll give you part of the script I use to rotate the hands of my watch.

Problem with this script though, is that it uses a timer that fires an event every second. I'll see if I can log in now.

>> ok, I finally logged in hehehe here's the code I use

CODE


float seconds;
float seconds_rot;

float minutes;
float minutes_rot;

float hours;
float hours_rot;

default
{
state_entry()
{
llSetTimerEvent(1);
}

timer()
{
// first we'll calculate the minutes
// llGetWallclock() will give you the total of seconds since midnight
// so we'll divide that by 60 to get the total of minutes since midnight
// since I couldn't find the Modulus function or whatever they might call it
// I calculate the total of complete hours since midnight (hence the llFloor()).
// This I multiply by 60, which gives me the minutes I have to substract from
// the total of minutes.

// calculating the seconds is somewhat the same.

minutes = (llGetWallclock() / 60) - (llFloor(llGetWallclock() / 60 / 60) * 60);
minutes_rot = (2 * -PI * (minutes / 60));

hours = llGetWallclock() / 60 / 60;
hours_rot = (2 * -PI * (hours / 12));

seconds = llGetWallclock() - (llFloor(minutes) * 60) - (llFloor(hours) * 60 * 60);
seconds_rot = (2 * -PI * (seconds / 60));
}
}


ok well.. this timer will give you the rotation in degrees for each hand.
This is how you would use these values you get to rotate a texture.

CODE

llRotateTexture(seconds_rot, ALL_SIDES);
Dreamstalker Xevious
Registered User
Join date: 28 May 2004
Posts: 29
02-27-2005 05:22
For script enhancing that, wouldnt it be better to call the llGetWallClock once, put it in a variable and use it throughout? Example:

CODE


timer() {
float fWallClockRetVal;
fWallClockRetVal = llGetWallclock();

minutes = (fWallClockRetVal / 60) - (llFloor(fWallClockRetVal / 60 / 60) * 60);
minutes_rot = (2 * -PI * (minutes / 60));

hours = fWallClockRetVal / 60 / 60;
hours_rot = (2 * -PI * (hours / 12));

seconds = fWallClockRetVal - (llFloor(minutes) * 60) - (llFloor(hours) * 60 * 60);
seconds_rot = (2 * -PI * (seconds / 60));
}



Wouldnt this help with Sim lag? I know in all the programming languages I work in, this would help shave off vital miliseconds (CPU Utilization) off runtime of the script / application. This way it only calls the function once, and then utilizes the variable instead of calling the function over and over again.

I ask this mostly to help my own scripting optimization and tips that would help with that. :)
FuRaz Chung
2Stylez Urban Wear
Join date: 25 Mar 2004
Posts: 27
02-27-2005 06:44
Yes, this would help :) Nice addition,

The best would be though to set the timer to 20 seconds or something and do the "seconds-hand" by animating the texture in stead of rotating it according to the llGetWallClock thing.

This would give you something like:

CODE


llSetTextureAnim(ANIM_ON | SMOOTH | LOOP | ROTATE, 0, 0, 0, 0, TWO_PI, -1 * (TWO_PI / 60));



Not too hard for somebody who went to math class ;)
_____________________
Founder of 2Stylez, first to introduce hip hop and urban to the Second World. People are still trying to kill me for that!