Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

strange behaviour with controls

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
05-12-2007 12:15
I have two scripts in two prims. one prim is the controller, the other is being controlled. the controller prim is very basic, shouts out "Left" "right" "up" "down" etc. on a channel. the prim being controlled hears the command is supposed to rotate itself accordingly. the problem is no matter what key I press the "left" command is sent out.

Controller
CODE

default
{
state_entry()
{
llSitTarget(<0,0,.1>,ZERO_ROTATION);
}

changed(integer change)
{
//llSay(0,"changed event");
if(change & CHANGED_LINK)
{
//llSay(0,"someone is sitting on me");
key user=llAvatarOnSitTarget();
if(user != NULL_KEY)
{
//llSay(0,"requesting controls");
llRequestPermissions(user,PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
}
}
}

run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
}
}

control(key id, integer held, integer change)
{
integer pressed = held & change;
float time=llGetTime();
if(time >=.2)
{
llResetTime();
//llSay(0,"control event");
if(pressed & CONTROL_LEFT|CONTROL_ROT_LEFT)
{
llSay(2809,"left");
}
else if(pressed & CONTROL_RIGHT|CONTROL_ROT_RIGHT)
{
llSay(2809,"right");
}
else if(pressed & CONTROL_FWD)
{
llSay(2809,"up");
}
else if(pressed & CONTROL_BACK)
{
llSay(2809,"down");
}

}
}
}



Receiving (controlled prim)
CODE

default
{
state_entry()
{
llListen(2809,"",NULL_KEY,"");
}

listen(integer channel, string name, key id, string message)
{
if(message=="left")
{
llSetRot(llEuler2Rot(llRot2Euler(llGetRot())+<-PI/8,0,0>));

}
else if(message=="right")
{
llSetRot(llEuler2Rot(llRot2Euler(llGetRot())+<PI/8,0,0>));
}

}
}


I've messed with the order that the if statements fall in, and it seems to be firing the first rotational keypress clause no matter what. any idea why this is?
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
05-12-2007 12:54
[edit]double post[/edit]
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.