Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

physical slow elevator

Horg Neurocam
Mineralogist
Join date: 28 Sep 2005
Posts: 19
02-12-2008 19:47
hallo! i'm attempting to use a publicly shared elevator script, but can't seem to get it to reset itself in any managable way. it either wants to hang in a physical floaty space, or simply drops to the bottom after i walk off of it. Can anybody pinpoint the problem? It moves great, i just can't seem to make it work in a repeatable fashion..

(And due to the sketchy searching powers here on the forums, i am unable to find out who originally posted the script, so my apologies!)

CODE

//Elevator Script

list Floors = ["mine","surface","whoknows!"]; // Floor names
list Offsets = [ 0, 15, -10 ]; // Z offsets, not really needed since all at 5m intervals

vector start_pos;
vector pos;
vector move_pos;

integer Listening = 0;
integer listenchannel = 0;

integer targetID;

ShowMenu(key id)
{
string text = "Lift Menu\nPlease Select a Floor";
UpdateListen(id);
llDialog(id,text,Floors,listenchannel);
}

UpdateListen(key id)
{
CancelListen();
listenchannel = - (integer)llFrand(2147483648);
Listening = llListen(listenchannel,"",id,"");
llSetTimerEvent(30);
}

CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}
init()
{
llSetStatus(STATUS_PHYSICS,FALSE);


llSetTimerEvent(10);
llSetText("",<0,0,0>,0);
}
default
{
state_entry()
{
init();
llSetStatus (STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
start_pos=llGetPos();
pos=start_pos;
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(start_pos,1.5);

}

touch_start(integer num_detected)
{
key id = llDetectedKey(0);
ShowMenu(id);
}

timer()
{
CancelListen();
}

listen(integer channel, string name, key id, string message)
{
CancelListen();
integer index = llListFindList(Floors,[message]);
if (index >= 0)
{
integer x = llList2Integer(Offsets,index);
move_pos=start_pos;
move_pos.z += x;
if (pos != move_pos)
{
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
}
}
}

run_time_permissions(integer perm)
{
llStartAnimation("impatient");
targetID = llTarget( move_pos, 0.1 );
llMoveToTarget(move_pos,5);
}

at_target( integer number, vector targetpos, vector ourpos )
{
llStopMoveToTarget();
//llSetStatus(STATUS_PHYSICS,FALSE); //hn line
if(targetID)
{
llStopAnimation("impatient");
llTargetRemove(targetID);
targetID = 0;
}
pos = llGetPos();
}
}


thanks for any helps!
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-15-2008 05:28
I only took a quick glance at the script and see the following problems(I & II), potential problems (III) and bad style(IV):

I. The script calls
llStopMoveToTarget();
but the next line
//llSetStatus(STATUS_PHYSICS,FALSE);
is commented out. The lift stays physical but it doesnt damp into a target. So gravity makes it fall down. Make sure the lift is physical before you call llMoveToTarget and make sure it is set to non-physical directly after you called llStopMoveToTarget();

II. The script relies on triggering the run_time_permissions event to move the lift and animate the avatar. Unfortunately the second time an avatar uses the lift this permission is already granted and llRequestPermissions doesnt trigger the run_time_permissions event any more.

III. critical damping (llMoveToTarget(endpos)) not always ends where you expect it. Especially with long damping times, when the transported avatar is heavier than your lift and with other objects nearby, the movement may well stop like 20 cm away from the target. but then the at_target event is not triggered (the script set it to 10 cm test distance).

IV. The test (pos != move_pos) wont work. Inequality tests for vectors should be of the form llVecMag(move_pos - pos) >= 0.1 . Otherwise you will always get true for the test.
(This wont break the script here, but in that case you could as well go without this test).