Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with choosing which loop to use

Screwtape Foulsbane
Registered User
Join date: 30 Dec 2007
Posts: 134
01-15-2008 15:38
I'm animating wings on a flying pig. I want to have them flap continously. I was using a while (count>100) for a short run and incermenting but it got stuck mid flap. Is there a better loop to use?

Thanks
S
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
01-15-2008 16:40
Just an infinite loop, not intended to be interruptible? Maybe just "while (TRUE)..." If it has to be able to be interrupted, you probably want to use a timer, so another event can get handled and turn off the timer.

(Hmm... Flying Pigs. Must be a Havoc 4 thing. :p )
Screwtape Foulsbane
Registered User
Join date: 30 Dec 2007
Posts: 134
01-15-2008 16:51
I intend on it being infinite. I made it to help get my mind around scripting as it's been 7 years since I've programed anything. I inten on making lots of silly things :P.

S
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-15-2008 21:24
do{
}while (TRUE); //-- do loops are reported to run faster than for or while loops by strife

is possibly the best option

you could also use a jump //-- should be the fastest requiring no test

if you want one that interupt you can only stop the above with a script reset or stop the running state from another script

to have it interuptable by other events the method would be to place your loop contents in the timer
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Screwtape Foulsbane
Registered User
Join date: 30 Dec 2007
Posts: 134
01-17-2008 16:58
Jump was too fast. The wings went out of sync quickly. I found the while loop did best.

Thanks for the assist
S
Whispering Hush
Join date: 20 Mar 2007
Posts: 277
01-17-2008 17:44
//flapping wings for m4d pigz
//
//luv whisper

integer flexi;
default
{
state_entry()
{
llSetTimerEvent(3.0);
}

timer()
{
if(flexi)
{
llSetPrimitiveParams([PRIM_FLEXIBLE, TRUE, 2, 0.5, 2.0, 0.0, 1.0, <0, 0, 0>]);
flexi = FALSE;
llMessageLinked(LINK_ALL_OTHERS, 1, "false", NULL_KEY);
}
else if (!flexi)
{
llSetPrimitiveParams([PRIM_FLEXIBLE, TRUE, 2, -0.5, 2.0, 0.0, 1.0, <0, 0, 0>]);
flexi = TRUE;
llMessageLinked(LINK_ALL_OTHERS, 1, "true", NULL_KEY);
}
}
}



default
{
link_message(integer sender_num, integer num, string str, key id)
{
if(str == "false";)
{
llSetPrimitiveParams([PRIM_FLEXIBLE, TRUE, 2, 0.5, 1.0, 0.0, 1.0, <0, 0, 0>]);
}
else if(str == "true";)
{
llSetPrimitiveParams([PRIM_FLEXIBLE, TRUE, 2, -0.5, 1.0, 0.0, 1.0, <0, 0, 0>]);
}
}

}
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
01-17-2008 19:26
Another option is to not use a script at all, if you have the prim-space. Use an animated texture.

If your wings are simply textured flat prims, you could use a four-frame texture. One frame with the wing texture, and three full-alpha frames. Use a script to first program each wing prim starting on the appropriate frame. Then delete the scripts. Next time you rez the pig, the wings should flap.

If your wings are puffy prims with solid textures, then use the same technique above, except with a solid first frame, and three full-alpha frames.

Ideally, once the animations are started with a script, and the object re-rezzed, the script may be deleted and no server effort is required to flap the wings.
Dogthinker Lemmon
Registered User
Join date: 26 Dec 2006
Posts: 5
01-17-2008 19:38
Whisper -
You might like to move the link message to before the llSetPrimitiveParams call, since llSetPrimitiveParams has a delay on it, so the wings would be flapping 0.2 seconds out of sync.

If you don't mind the 0.2 seconds out of sync, you could even use llSetLinkPrimitiveParams to cut down to one script only.


Oh, and that's a lovely trick to use the flexi to flap the wings. Would look nicer, and with the timer it less work for the server than working a loop endlessly, I think.
Whispering Hush
Join date: 20 Mar 2007
Posts: 277
01-17-2008 19:53
From: Dogthinker Lemmon
Whisper -
You might like to move the link message to before the llSetPrimitiveParams call, since llSetPrimitiveParams has a delay on it, so the wings would be flapping 0.2 seconds out of sync.

If you don't mind the 0.2 seconds out of sync, you could even use llSetLinkPrimitiveParams to cut down to one script only.


Oh, and that's a lovely trick to use the flexi to flap the wings. Would look nicer, and with the timer it less work for the server than working a loop endlessly, I think.



mmmm no visible delay. try it.

thanks for the llSetLinkPrimitiveParams tip :-)