Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Control Issues (Try #2)

Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
02-20-2006 10:14
I posted about this a few months ago, and now I'm willing to post my code in order to get an answer.

A few months back, I decided to write myself a flight booster script. I know there are free ones out there that work great, but I wanted the experience of writing my own. The flight functionality works perfectly, but it has one hitch that I can't figure out: When it switches states (in this case that also involves taking and releasing controls) it releases the controls for any other attachments I'm wearing as well, such as any sort of scripted weapon.

Given that there are freebie flight boosters out there that work just as well, I feel comfortable posting my work so people can analyze it. If anyone has any insight into what's causing my problem, please tell!

Also, I've never posted code before, so if this is ugly, I wouldn't mind some enlightenment there too :-)

CODE

float power = 10.0;

default
{
state_entry()
{
llSetBuoyancy(0.0);
llSetTimerEvent(1.0);
llListen(0, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string msg)
{
if (llGetSubString(msg, 0, 2) == "fwf")
{
power = (float)llGetSubString(msg, 3, -1);
llOwnerSay("Power = " + (string)power);
}
}

attach(key attached)
{
if (attached != NULL_KEY)
{
llResetScript();
}
}

timer()
{
if(llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
{
//llOwnerSay("Flying");
state flying;
}
}
}

state flying
{
state_entry()
{
vector pos = llGetPos();
if((pos.z - llGround(<0,0,0>)) > 53)
{
llSetBuoyancy(1.0);
}
llSetTimerEvent(1.0);
llListen(0, "", llGetOwner(), "");
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}

state_exit()
{
llReleaseControls();
}

listen(integer channel, string name, key id, string msg)
{
if (llGetSubString(msg, 0, 2) == "fwf")
{
power = (float)llGetSubString(msg, 3, -1);
llOwnerSay("Power = " + (string)power);
}
}

attach(key attached)
{
if(attached != NULL_KEY)
{
}
else
{
llReleaseControls();
}
}

timer()
{
if(llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
{
}
else
{
//llOwnerSay("Not Flying");
state default;
}

vector pos = llGetPos();
if((pos.z - llGround(<0,0,0>)) > 53)
{
llSetBuoyancy(1.0);
}
else
{
llSetBuoyancy(0.0);
}
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, TRUE);
}
}

control(key id, integer held, integer change)
{
if(held & CONTROL_UP)
{
llApplyImpulse(<0,0,power>, TRUE);
}

else if(held & CONTROL_DOWN)
{
llApplyImpulse(<0,0,-power>, TRUE);
}

else if(held & CONTROL_FWD)
{
llApplyImpulse(<power,0,0>, TRUE);
}

else if(held & CONTROL_BACK)
{
llApplyImpulse(<-power,0,0>, TRUE);
}

else if(held & CONTROL_RIGHT)
{
llApplyImpulse(<0,-power,0>, TRUE);
}

else if(held & CONTROL_LEFT)
{
llApplyImpulse(<0,power,0>, TRUE);
}
}
}
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
02-20-2006 14:57
Don't release the controls?
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
02-20-2006 15:48
From: Argent Stonecutter
Don't release the controls?


That is an option, but other flight scripts don't have to make this compromise, so why should I? The point of this exercise is to figure out why releasing controls on one attachment releases controls for another attachment. If I didn't release controls on the flight script, and I released controls on another attachment, I wouldn't want to lose the flight too! Just my thoughts.