Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problem iwth link messages

Dogma Trevellion
Registered User
Join date: 11 Feb 2008
Posts: 1
12-11-2008 22:56
Hi everyone

Im trying to script a single prim in an object to rotate either up or down when a prim button in the object is clicked. Problem is the object keeps hearing both commands no matter which button I click
I have stripped it down to 4 parts, the root prim, then prim #2 which I want to rotate, prim #3 is the up button and prim #4 is the down button

Trail and error and inexperiance have gotten me to this point:

I put this script in prim #4
***************************
string down = "down";

default
{
state_entry()
{

}

touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT, 1, down, "";);
}
}


then a similar script in Prim #3
**************************************
string up = "up";

default
{
state_entry()
{

}

touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT, 1, up, "";);
}
}

In the root prim I have 2 scripts acting as relays
******************************************d
efault
{
state_entry()
{

}


link_message (integer sender_num, integer num, string str, key id)

{

(sender_num == 3 & str == "up";);
llMessageLinked (LINK_ALL_CHILDREN, 1, "raise", NULL_KEY);
}

}

and
**********************************
default
{
state_entry()
{

}


link_message (integer sender_num, integer num, string str, key id)

{

(sender_num == 4 & str == "down";);
llMessageLinked (LINK_ALL_CHILDREN, 1, "lower", NULL_KEY);
}


}


THen in prim #2, the prim I want to rotate, I have these two scripts
****************************************************

integer angle_increment = 5;
integer no_of_inclination_moves = 1;


default
{
state_entry()
{

}

link_message( integer sender_num, integer num, string str, key id)
{

(sender_num == 1 & str == "lower";);
{
llWhisper( 0, "Lowering 5 Degrees";);


rotation z_inc = llEuler2Rot( <0, angle_increment * DEG_TO_RAD, 0> );
rotation new_rot = z_inc*llGetRot();
no_of_inclination_moves = no_of_inclination_moves + 1;
llSetRot(new_rot);
integer ma = angle_increment* no_of_inclination_moves;



}

}
}

************************************
integer angle_increment = 5;
integer no_of_inclination_moves = 1;


default
{
state_entry()
{

}

link_message( integer sender_num, integer num, string str, key id)
{



(sender_num == 1 & str == "raise";);
{
llWhisper( 0, "Raising 5 Degrees";);


rotation z_inc = llEuler2Rot( -(<0, angle_increment * DEG_TO_RAD, 0>;) );
rotation new_rot = z_inc*llGetRot();
no_of_inclination_moves = no_of_inclination_moves - 1;
llSetRot(new_rot);
integer ma = angle_increment* no_of_inclination_moves;

}
}
}


When I click either of the buttons though prim #3 does the commands of both buttons, so it goes up and right back down. I know this might seem a round about way to do this but this is just me trying to figure it out from scratch a bit. Can someone tell me what Im doing wrong?

Thanks!
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-11-2008 23:52
If you want to have each prim that gets touched run its own script, you will want to call llPassTouches(FALSE) in the children so that they don't propagate. (looks like your root isn't trying to process touches, but i'm thinking that you are getting two touch events started here when you wanted one)

http://wiki.secondlife.com/wiki/LlPassTouches

As an alternative, you could use one script in the root to process all the touches, using something like llDetectedLinkNumber (perhaps check that prim's name so you don't need to keep track of the numbers) to find out which prim was touched. llDetectedLinkNumber etc. might be useful in the script-per-prim setup too, to make sure stray touches really haven't been passed.

(actually looking more, maybe you do just want the touch event in the root, one script, since you are already looking at link numbers. Use the detected link number in a touch event to decide, in a single root prim script, if you want to send "raise" or "lower" out.)
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
12-12-2008 03:08
Also the tests in your link_message event are wrong.

For example

link_message (integer sender_num, integer num, string str, key id)

{

(sender_num == 4 & str == "down";);
llMessageLinked (LINK_ALL_CHILDREN, 1, "lower", NULL_KEY);
}

Should be

link_message (integer sender_num, integer num, string str, key id)

{

if (sender_num == 4 && str == "down";)
llMessageLinked (LINK_ALL_CHILDREN, 1, "lower", NULL_KEY);
}

At the moment all scripts will resond to any link message because without an if there is no test :)