Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Timer vs. Sleep AND cyclic linear motion

Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
09-24-2007 19:14
I want to llSetPos every .2 seconds (because there is a .2 second sleep with each call of the function.

Since I call this in a timer event, do I set the timer event to fire every .2 seconds? Or every .0001 second? Does the .2sec sleep affect the timer frequency?

Oh, and what I *really* want to do is call llSetPos more than once every .2 seconds. Any simple tips for using multiple scripts to call it, way, every .05 seconds? I want to move something like a piston, in a cyclic motion (but in a straight line).

Thanks,
Baron
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
09-25-2007 00:08
Timers run asynchronously with the script, so with the 0.2 second built-in sleep, there'd be no point in setting the timer interval any smaller than 0.2 seconds.

The general pattern for multiple scripts is just to llMessageLinked to LINK_THIS, where the slave scripts trigger by matching "their" number as the integer part of the link_message. One might use the string part to pass the motion parameters the script should execute.

Depending what's actually intended for the motion, a little experimenting with llMoveToTarget may possibly be worthwhile. It gives smoother motion than a bunch of calls to llSetPos, if that happens to be the objective.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
09-25-2007 00:13
title your scripts "piston 0", "piston 1", etc

then try this
CODE

integer vIntPiston = (float)llGetSubString( llGetScriptName(), 7, 7 );
//-- change these to suit you
vector CONSTANT_THAT_EQUALS_POSITION = <0,0,0>;
vctor CONSTANT_THAT_EQUALS_REST_POSITION = <0,0,0>;

default{
state_entry(){
}

link_message( integer vIntNull, integer vIntCode, string vStrNull, key vKeyNull){
if (vIntCode == 123){
llSleep( gIntPiston / 4.0
llSetPos( CONSTANT_THAT_EQUALS_POSITION );
llSetPos( CONSTANT_THAT_EQUALS_REST_POSITION );
}

}
and in your main script
CODE

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

timer(){
llMessageLinked( LINK_ROOT, 123, "", "" );
}
}


any faster and you'll need to have a seperate script for both up and down states
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
09-25-2007 06:06
Ahhh, thank you. Was trying to do this nearly in sleep . . . tried using one link message and various sleeps in the child scripts. That did not work. But I see now, multiple link messages sound like they will do what I want.

I tried using llMoveToTarget, but because of overlapping prims, I cannot make it physical.

I will try this . . . thanks!!!