Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vehicle problem I can't work out - please help!

Ajh Aeon
Registered User
Join date: 3 Mar 2008
Posts: 1
03-09-2008 20:37
Hi,

I'm working on making a Dragonfly using an altered version of the basic Airplane script. I'm getting 2 errors I just don't understand.

1) Sometimes the script works, I can fly around. Then if I take it back into my inventory the next time I use it, it might work or instead of flying I just sit on the object. If I change the script (even adding a space) and save, sometimes it can work again, othertimes not. I just can't work out why it works some times and not others.

2) I sometimes get scripting errors but they mention a previous version of the object. I've taken copies of the object, renamed it and renamed the script but I still sometimes get these script errors (about Permission) referring to the old version. I even deleted all the old versions I had with the name it refers to (and deleted my Trash) but it's still happens. Again only happens sometimes.

I will add the script at the bottom of this thread, but any help would be very, very appreciated. This is driving me crazy and I keep staring at the script, trying different things, searching for answers but I still get these 2 issues. Help Please!

//Simple Airplane Script Example by Andrew Linden
//http://forums.secondlife.com/showthread.php?t=7134
//-----------------------------------------------------
//modified by Kim Anubis, July 5, 2007
//modified by Alex Hamper, February 2008

// changed this airplane script for a dragonfly

// assumes that the root primitive is oriented such that its
// local x-axis points toward the nose of the plane, and its
// local z-axis points toward the top

// control flags that we set later
integer gAngularControls = 0;
integer gLinearControls = 0;

// we keep track of angular history for more responsive turns
integer gOldAngularLevel = 0;

//counting how many collisions take place. (Note one collision can accout for 10 - 15 collision points)
integer collisions = 0;
integer reproach = 0;

// the linear motor uses an accumulator model rather than keeping track
// of the linear control level history
vector gLinearMotor = <0, 0, 0>;

default
{
//KA Added this so the plane would recognize its new owner and also not take off if it had been picked up while still running.
on_rez(integer start_param)
{
llResetScript();

}

state_entry()
{

llSetSitText("Fly";);
llCollisionSound("", 0.0);

// Setting the avatar sitting (riding) position to just on the Dragonfly body, facing in the right direction and I've changed the camera position to be nearer to the avatar
llSitTarget(<0.0, 0.0, 0.4>, <0,0.0,0,1>;);
llSetCameraEyeOffset(<-5.0, 0.0, 2.0>;);
llSetCameraAtOffset(<3.0, 0.0, 1.0>;);

llSetVehicleType(VEHICLE_TYPE_AIRPLANE);

// weak angular deflection
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 1.0);

// strong linear deflection
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.2);

// changed to 1.0 sec motor because it was too quick.
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 20);

// somewhat responsive angular motor, but with 3 second decay timescale
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 3);

// very weak friction
//KA The following value was set at 10000,10000,1000 and I wanted to make the plane easier to handle and less likely to move by itself.
llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1.0, 1.0, 1.0>;);

//KA Reducing these made it easier to handle, too -- finally able to land it.
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10.0, 10.0, 100.0>;);

llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.25); // almost wobbly
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1.5); // mediocre response

//KA Let's bank into turns a little tighter
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.7); // medium strength
//KA Turned up the following a little so the plane would be a bit more forgiving though, so we don't end up doing what hang glider pilots call "ground loops"
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.95); // more banking when moving

//AJH Turned these on.
llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 1.0);
llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.5);
llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 2.0);
llSetVehicleFlags(VEHICLE_FLAG_HOVER_UP_ONLY);

// non-zero buoyancy helps the airplane stay up
// set to zero if you don't want this crutch
llSetVehicleFloatParam(VEHICLE_BUOYANCY, 0.2);

// define these here for convenience later
gAngularControls = CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT
| CONTROL_ROT_LEFT | CONTROL_DOWN | CONTROL_UP;
gLinearControls = CONTROL_FWD | CONTROL_BACK;
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
//if (agent != llGetOwner())
// {
// // only the owner can use this vehicle
// llSay(0, "You aren't the owner";);
// llUnSit(agent);
// llPushObject(agent, <0,0,10>, ZERO_VECTOR, FALSE);
// }
// else
// {

// clear linear motor on successful sit
gLinearMotor = <0, 0, 0>;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);

//KA commented the following back in, because I have had trouble with the plane running away by itself.
llSetStatus(STATUS_PHYSICS, TRUE);
//KA We need more drag, so we don’t need this.
//llSetVehicleFloatParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, 1000.0);
//KA or this either
//llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 1000.0);
llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
// }
}
else
{
// stop the motors
gLinearMotor = <0, 0, 0>;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, gLinearMotor);

//KA commenting out the following two lines about friction and uncommenting Status_physics, false so the plane will stop running away by itself
// use friction to stop the vehicle rather than pinning it in place
llSetStatus(STATUS_PHYSICS, FALSE);
//llSetVehicleFloatParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, 1.0);
//llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 1.0);

// driver is getting up
llReleaseControls();

//KA Added our unseating message to the other scripts in the plane
llMessageLinked(LINK_SET, 0, "unseated", "";);
//KA Added this to turn off our sound loop.
llStopSound();
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{

//KA Added this to turn on our sound loop.
llLoopSound("insect wings",1.0);
//KA Added our seating message to the other scripts in the plane
llMessageLinked(LINK_SET, 0, "seated", "";);
llTakeControls(gAngularControls | gLinearControls, TRUE, FALSE);
}
}

//Dragonfly speaks if too many collisions
collision_start(integer num_detected)

{
collisions = collisions +1;

if (collisions >=150 && collisions <=300)
{
if (reproach ==0)
{
llSay(0, "Bumpy Ride";);
reproach = 1;
}
}
else if (collisions >300 && reproach ==1)
{
llSay(0, "There are flight lessons on the help island you know!";);
reproach = 2;
}
else if (collisions >450 && reproach ==2)
{
llSay(0, "Ouch!!! My wings hurt!";);
reproach = 3;
}
}




control(key id, integer level, integer edge)
{
// only change linear motor if one of the linear controls are pressed
vector motor;
integer motor_changed = level & gLinearControls;

if (motor_changed)
{
if(level & CONTROL_FWD)
{
if (gLinearMotor.x < 0)
{
gLinearMotor.x = 0;
}
else if (gLinearMotor.x < 30)
{
gLinearMotor.x += 5;
}
motor_changed = TRUE;
}
if(level & CONTROL_BACK)
{
if (gLinearMotor.x > 0)
{
gLinearMotor.x = 0;
}
else if (gLinearMotor.x > -30)
{
gLinearMotor.x -= 5;
};
motor_changed = TRUE;
}
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);
}

// only change angular motor if the angular levels have changed
motor_changed = (edge & gOldAngularLevel) + (level & gAngularControls);
if (motor_changed)
{
motor = <0,0,0>;
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
// add roll component ==> triggers banking behavior
motor.x += 10;
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
motor.x -= 10;
}
if(level & (CONTROL_UP))
{
// add pitch component ==> causes vehicle lift nose (in local frame)
motor.y -= 8;
}
if(level & (CONTROL_DOWN))
{
motor.y += 8;
}
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, motor);
}
// store the angular level history for the next control callback
gOldAngularLevel = level & gAngularControls;
}
}
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
03-10-2008 08:15
hmm...

well, i think you can avoid the first problem by putting an llResetScript(); into an on_rez event. that way, every time you rez it out of your inventory, the script is reset. (which is what the adding a space and saving is doing.)


as for the other error.... okay, that's a wild one. could it be an error from the other prims in the object (whatever the link message is talking to)? you could have a child prim that still has 'dragonfly 0.00009' as a name, even if you rename the whole object. but... only if you named all the objects when you built it. or named the base prim you copied from (i do that a lot).

just a thought. :/
_____________________
Why Johnny Can't Rotate:
http://forums.secondlife.com/showthread.php?t=94705