Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Child Prim Position Question

Quick Stilman
Registered User
Join date: 3 Apr 2006
Posts: 4
08-20-2006 10:50
Hi all,

I am hoping that someone will be able to help me. I am trying to script drapes for a canopy bed that will open and close. I have made a simple script to move a child object a set distance along the X-axis of the parent (using llsetpos and llgetlocalpos).On each side of the drapes, I have 3 flexi strips that move away from each other to a given point. I have this set to voice command so that when the command is given all the objects move along the axis.

The script works, but the problem is that I can open the drapes and then open them again so that the ojects get farther away from each other and move off the bed. I tried the wiki to figure out how to get child objects to return to their original position relative to the parent, but I can't seem to get the llsetpos() command to work is a way to get the child objects to return.

Can anyone point me in the right direction?

Here is the simple code I have so far:
CODE

default
{
state_entry()
{
llListen( 559, "", NULL_KEY, "" );
}
listen(integer channel, string name, key id, string message)
{

if (llToLower(message) == "open")
{
llSetPos(llGetLocalPos() + <2, 0, 0>);
}
if (llToLower(message) == "close")
{
llSetPos(llGetLocalPos() + <2, 0, 0>);
}
}
}
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
08-20-2006 12:06
just a note, but you have both "open" and "close" command move your child object farther and farther away in the same direction (both add 2 m to current position)

with that out of way, states can be probably quite convenient way to deal with this.
CODE

vector shift = <2.0, 0.0, 0.0>;

default {

state_entry() { state open; } // for extra points could check local pos() instead, to determine current state
}

state open {

state_entry() {

llSetPos( llGetLocalPos() + shift );
llListen( 599, "", llGetOwner(), "close" );
}

listen(integer channel, string name, key id, string message) { state close; }
}

state close {

state_entry() {

llSetPos( llGetLocalPos() - shift );
llListen( 599, "", llGetOwner(), "open" );
}

listen(integer channel, string name, key id, string message) { state open; }
}

this prevents your item to execute the same command more than once, because it no longer recognizes command to 'open' once it's in 'open' state etc. Thogh that said, using separate listen handles for muliple child items will have some impact on sim performance ... touch() with link_messages could be probably nicer o.x;
Quick Stilman
Registered User
Join date: 3 Apr 2006
Posts: 4
Thanks!
08-20-2006 15:48
Thanks a ton for the help. It worked great. I will have to look into how to script it for touch start. I am very new to scripting and there were going to be 14 moving partsin 3 diffrent linked objects, so I thought that voice command might be easiest with my limiited knowledge.

I really apprecaiate the help!
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-20-2006 15:49
Or set up the state check switch.
CODE
integer is_opening = FALSE;

default
{
state_entry()
{
llListen( 559, "", NULL_KEY, "" );
}
listen(integer channel, string name, key id, string message)
{

if (llToLower(message) == "open" && is_opening == FALSE)
{
llSetPos(llGetLocalPos() + <2, 0, 0>);
is_opening = TRUE;
}
if (llToLower(message) == "close" && is_opening == TRUE)
{
llSetPos(llGetLocalPos() + <2, 0, 0>);
is_opening = FALSE;
}
}
}
_____________________
:) Seagel Neville :)
Norman Desmoulins
Grand Poohba
Join date: 10 Nov 2005
Posts: 194
08-20-2006 16:04
Another way to do it is with texture change. Put the cells of the anim in one texture and just change the offset for each cell. This way you can give the appearance of it bunching together as it opens, and smooth out as it closes.