Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

timer help

Jade Bard
Registered User
Join date: 7 Jul 2004
Posts: 106
08-12-2004 07:42
so you can't have 2 timers in the same script right?

So could i create a second script in the same object, and have that have a timer, but how would the 2 scripts speak to each other if they are in the same object?


Help anyone
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
08-12-2004 07:55
You can't have two timers, but you can fake it
CODE



integer nTimeOut1 = 3; /* do something every 3 seconds, for example */
integer nTimeOut2 = 4; /* every 4 seconds */
integer nTime = 0;

timer1()
{
/* do stuff */
}

timer2()
{
/* do other stuff */
}

default{
state_entry()
{
llSetTimerEvent(1.0);
}
timer()
{
nTime++;
if ((nTime % nTimeOut1) == 0) timer1();
if ((nTime % nTimeOut2) == 0) timer2();
...
}
}


if you really want to have two different scripts in the same object talking to each other, you can use link messages. Look up llMessageLinked.
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Jade Bard
Registered User
Join date: 7 Jul 2004
Posts: 106
08-12-2004 08:04
actually i'm just using llGetTime(), and llResetTime() with my timer. It works fine.
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
09-09-2004 11:49
If you were using more than one prim in your project, each prim can have a script in it that can communicate with the prime prim.

What would happen if you wanted to do two scripts in the same prim though? Is that hard to send linked messages to a script in the same prim?
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
09-09-2004 12:51
From: someone
Originally posted by Samhain Broom
What would happen if you wanted to do two scripts in the same prim though? Is that hard to send linked messages to a script in the same prim?


Not hard at all Samhain..

e.g.
CODE

llMessageLinked(llGetLinkNumber(), 0, "", NULL_KEY)


llGetLinkNumber() will obtain the link number of the prim the script resides in, so you essentually send link messages to itself.
_____________________
All under heaven...