Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Timer problems

Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
03-04-2006 14:59
Ok....... what I am trying to do is to rotate the hands on a clock - hours, minutes, seconds.

This is the script I have created:

From: someone

default
{
state_entry()
{
llTargetOmega(<0.0166667,0,0>,PI,1.0);

llSetTimerEvent(1);
}

timer()
{

}
}


So basically rotate the hand 1/60th of a turn, then pause 1 second, repeat.

For the minutes, I pause 60 seconds in the llSetTimerEvent - and for hours, rotate 360 seconds.

However... it seems to be completely ignoring the timer, and rotates all 3 hands at exactly the same speed.

It must be something obvious I've done wrong - but I can't figure it out.

Any help gratefully appreciated.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
03-04-2006 15:14
A word of warning: llTargetOmega is a client-side effect, and is HIGHLY suceptible to drift. You may not get an acceptable effect using it, and everyone will see a slightly different time, which may or may not be close to what you want.

Your best option is to use llSetRot. (Or llSetPrimitiveParams, if you need to set both position and rotation at once, depending on how your clock is designed.)
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
03-04-2006 15:36
In the code you provided above, your timer event isnt doing anything (you have no code in the timer event). llTargetOmega takes a vector as its first parameter that's easiest to work with if its normalized. It makes it so that the second parameter is the speed (in rads/sec) that its going around. For nonphysical objects, the third parameter doesnt matter.

For your second hand, youll want:
llTargetOmega(<1, 0, 0>, TWO_PI, 1.0);
We want it to go TWO_PI radians (a full circle) in 1 second.

For your minute hand, you want:
llTargetOmega(<1, 0, 0>, TWO_PI/60, 1.0);
So it goes only one sixtieth of a full circle (one hour) per second.

and for your hour hand:
llTargetOmega(<1, 0, 0>, TWO_PI/3600, 1.0);
The hour hand travels around the circle in 1/60th of the time the minute hand does, making it 1/3600th the time the second hand does. (Its all relative to the second hand because the speed here is in radians/second.)

Keep in mind what Catherine said is going to affect this. You may want to use the targetOmega replacement function I posted in the commentary section of the llTargetOmega wiki page to synchronize the server's view of the clock's rotation with that of the clients every so often. llTargetOmega "starts" the rotation of the object when it first comes into a person's view, so when people first "see" the clock, its going to read a wrong time.

Hope this helps! :D
==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
03-04-2006 19:03
To make an accurate clock, it's a big pain to use llTargetOmega for the minute or hour hands. What you want to do is to make a disc with time-sync code similar to the stuff I posted in the other thread... with the timer doing something like:

CODE

timer()
{
if(minute_hand)
llSetRot( llGetRootRot()*<0,0,(integer)(llGetWallclock()/60) % 60)*PI/30> );
else //hour_hand
llSetRot( llGetRootRot()*<0,0,(integer)(llGetWallclock()/60) % (12*60)) * PI/360> );
sync_time();
}


The second hand can just use llTargetOmega(...);.
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
03-05-2006 00:36
Still don't get it. This should be so simple but it just doesn't seem to want to happen.

How much do people charge to write something like this?

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
03-05-2006 02:24
From: someone
How much do people charge to write something like this?
A true nerd would head down to Yadni's, find one of a dozen free, open script clocks and steal that. Or in your case, I'd do it for under L$40k.
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
03-05-2006 03:04
From: Introvert Petunia
A true nerd would head down to Yadni's, find one of a dozen free, open script clocks and steal that. Or in your case, I'd do it for under L$40k.


I wasn't aware there were any. I'll head on down and have a poke around see what I can find.

Thank you for your quote. I should have that amount of money together by the end of June 2007.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
03-05-2006 03:41
Couldn't find one at YadNi's but I did find a useable one for L$50 at a place called Clockworx (Achlya 192, 251, 93) which seems a reasonable compromise. I've asked the owner a few questions as its not ideal for my needs but its much better than the half-assed attempts I've made myself.

Lewis (WWID)
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-05-2006 10:03
You should use llSleep(); it's alot simpler and you don't have to use the timer event, you can just have all the commands in front of each other in the same state.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
03-05-2006 10:47
From: Exile Loudon
You should use llSleep(); it's alot simpler and you don't have to use the timer event, you can just have all the commands in front of each other in the same state.


Right, but that won't change the fact that sleeping in the script doesn't affect an llTargetOmega() that's already in effect...
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
03-05-2006 13:32
From: Exile Loudon
You should use llSleep(); it's alot simpler and you don't have to use the timer event, you can just have all the commands in front of each other in the same state.
That really doesn't change the difficulty of the problem here, because there's only one thing you're doing. The two versions of the code would only be a few lines different:
CODE

state default
{
state_entry()
{
while(1)
{
move_hand();
llSleep(calculate_next_tick());
}
}
}

Instead of:
CODE

state default
{
state_entry()
{
llSetTimerEvent(0.1); // prime the pump
}
timer()
{
move_hand();
llSetTimerEvent(calculate_next_tick());
}
}