Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Regular Timer

Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
04-28-2007 09:16
This script syncs to the wall clock. If you set interval to N (which can be a float), the action() is called at N, 2*N, 3*N, etc. Other timers sync to time since reset or time since creation, this one does not. It also attempts to adjust itself if SL is slow (or fast 8-) 8-).

Because it is sync'ed to the wall clock, several objects will act in unison, give or take a couple hundreths of a second.

CODE

// Regular clock ticker.
// Set interval to some number of seconds
//
// Put a call to perfomr some actions in action().
//
// Object will perform action() every interval seconds. If there are more than
// one, they will work in synch.
//
// Lee Ponzu, no rights reserved


float interval = 3.0; //seconds between actions
float inv;
float acc = .01;

action()
{
// put the action that should be performed here

llSetRot( llGetRot()*llEuler2Rot(<0,0,PI_BY_TWO>) );
}

// Gets the number of milliseconds since midnight UTC.
// GetGMTmsclock() is by ...damn, can't find it. Thanks though.

integer GetGMTmsclock()
{
string stamp = llGetTimestamp();
return
(integer) llGetSubString(stamp, 11, 12) * 3600000 +
(integer) llGetSubString(stamp, 14, 15) * 60000 +
llRound((float) llGetSubString(stamp, 17, -2) * 1000.0);
}

float GetTime()
{
return GetGMTmsclock()*.001;
}


default
{
state_entry()
{
llOwnerSay( "entering default state");
llSetTimerEvent(interval);
inv=1.0/interval;
}
on_rez(integer n)
{
llOwnerSay("rezzing");
//tick = llGetTime();
}

touch_start(integer total_number)
{
llSay(0, "Touched.");
llSleep(10);
}

timer()
{
float now = GetTime();
float count = now*inv;
// invariant is for count to be close to an integer, and
// delta to be zero

float delta = interval*(count - llRound(count));
if(llFabs(delta) > acc)
llSetTimerEvent( interval-delta );

// this is where the action would go...

action();

}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-29-2007 15:32
/54/1c/180578/1.html
_____________________
i've got nothing. ;)
Man Monnett
Registered User
Join date: 4 Jun 2006
Posts: 6
Perfect ... but
05-06-2007 00:45
This script is simply perfect. I use it to strike a bell every so many seconds ... but how would i get it to strike by the hour and still use this script to 'hit' the bell?