Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Elevator Problem

JustinMichael Torok
Old builder, new scripter
Join date: 29 Jul 2008
Posts: 23
01-07-2009 20:29
I'm working on this script in LSL Editor. It's supposed to act as an elevator and shift an avatar in 8m intervals along the z-axis. My problem is that the elevator isn't moving. The text-based simulator in LSL Editor displays the position of the elevator and it moves just find in the simulation. When I put the script in my elevator, it won't move at all. Anyone see a problem with it?

CODE

vector position; //Base Position
default
{
state_entry()
{
position = llGetPos();
llSay(0, (string)position);
llListen(13,"","","");
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE);
}

listen(integer channel, string name, key id, string message)
{
if(llGetPos() == position)
{
if(message == "first")
{
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
else if(message=="second")
{
//llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
else if(message == "third")
{
//llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 16>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
else if(message == "roof")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 24>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
//llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llGetPos() == (position + <0, 0, 8>))
{
if(message == "first")
{
//llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message == "second")
{
llWhisper(0, "Second Floor.");
}
if(message == "third")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
if(message == "roof")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 16>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llGetPos() == (position + <0, 0, 16>))
{
if(message == "first")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 16>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message=="second")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
if(message == "third")
{
llWhisper(0, "Third Floor.");
}
if(message == "roof")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llGetPos() == (position + <0, 0, 24>))
{
if(message == "first")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 24>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message=="second")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 16>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
if(message == "third")
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
if(message == "roof")
{
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
// llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
}
}
_____________________
Error 407: Unhandled exception in Galaxy 9.
Reboot Universe? Y/N
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
01-07-2009 20:44
Is the elevator object physical?

All the llSetStatus(STATUS_PHYSICS,TRUE); lines in your script are commented out, so unless you turned on physics on the object yourself, it won't move.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-07-2009 22:16
I'd be very careful about using '==' on floating point positions (vectors). It is much safer to compare the difference to some tolerance/threshold. I would change all of those to something like 'if (llVecDist(pos1, pos2) < EPSILON)...'.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
01-07-2009 22:26
Also, if the elevator is too massive, it won't move, as it will take more energy than llMoveToTarget can generate. Make sure to hollow out prims as much as possible to reduce mass.
JustinMichael Torok
Old builder, new scripter
Join date: 29 Jul 2008
Posts: 23
01-08-2009 11:25
I reduced the mass of the elevator as much as possible and used the llVecDist function instead of "==". The elevator still won't move :( Anyone have some free time to look at this? There are multiple buttons sending commands to the elevator. Anyone see a problem with these?

New Main Script:

CODE


vector position; //Base Position
default
{
state_entry()
{
position = llGetPos();
llSay(0, (string)position);
llListen(13,"","","");
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE);
}

listen(integer channel, string name, key id, string message)
{
if(llVecDist(position, llGetPos()) <= 1)
{
if(message == "first")
{
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
else if(message=="second")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
else if(message == "third")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 16>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
else if(message == "roof")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 24>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llVecDist(position, llGetPos()) <= 9)
{
if(message == "first")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message == "second")
{
llWhisper(0, "Second Floor.");
}
if(message == "third")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
if(message == "roof")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 16>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llVecDist(position, llGetPos()) <= 17)
{
if(message == "first")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 16>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message=="second")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
if(message == "third")
{
llWhisper(0, "Third Floor.");
}
if(message == "roof")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() + <0, 0, 8>, 1.5);
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
else if(llVecDist(position, llGetPos()) <= 25)
{
if(message == "first")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 24>, 1.5);
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
if(message=="second")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 16>, 1.5);
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
if(message == "third")
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos() - <0, 0, 8>, 1.5);
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
if(message == "roof")
{
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
llSay(13, "Arrive");
}
}
}
}


First Floor Button:

CODE

// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano)
default
{
touch_start(integer total_number)
{
llSay(13, "first");
}
}


Call Elevator to Location Button:

CODE

// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano)
vector Position;
default
{
state_entry()
{
Position = llGetPos();
Position -= <0, 0, 2>;
}
touch_start(integer total_number)
{
llSay(13, (string)Position);
}
}


Door Open Script:

CODE

// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano)
rotation BaseRot;
default
{
state_entry()
{
llListen(13, "", "", "");
}
touch_start(integer total_number)
{
llWhisper(0, "Please press the call button.");
}
listen(integer channel, string name, key id, string message)
{
if(message == "Arrive")
{
BaseRot = llGetRot();
rotation z_55 = llEuler2Rot( <0, 0, 55 * DEG_TO_RAD> );
rotation new_rot = z_55 * llGetLocalRot(); // compute local rotation
llSetLocalRot(new_rot); // orient the object accordingly
llSetTimerEvent(5);
}
}
timer()
{
llSetRot(BaseRot);
llSetTimerEvent(0);
}
}


Thanks :)
_____________________
Error 407: Unhandled exception in Galaxy 9.
Reboot Universe? Y/N
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
01-08-2009 12:39
if i remember right llMoveToTarget doesn't do much unless you explicitly invoke llSetTarget first (and subsquently remove it with llRemoveTarget in the at_target event...
_____________________
http://slurl.com/secondlife/Together
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-08-2009 13:15
From: Escort DeFarge
if i remember right llMoveToTarget doesn't do much unless you explicitly invoke llSetTarget first (and subsquently remove it with llRemoveTarget in the at_target event...

That's not correct. llSetTarget() offers COMPLETELY different functionality from llMoveToTarget(). The former just informs you if you are close to a specified point. The latter applies a force toward a specified point. They can be useful when applied together, but it isn't necessary by any means.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-08-2009 13:25
Does it move at all? Little wiggle? Are there objects around it that might be interfering with its movement? Try it in a wide open field or something.
JustinMichael Torok
Old builder, new scripter
Join date: 29 Jul 2008
Posts: 23
01-08-2009 14:01
I experimented with just the llMoveToTarget, and I noticed something that might become a problem. The object must be physical to move, right? Well, I'm using a flat cylinder as my elevator object. When an avatar stands on it off-balanced, it flips over. Any way around this?
_____________________
Error 407: Unhandled exception in Galaxy 9.
Reboot Universe? Y/N
JustinMichael Torok
Old builder, new scripter
Join date: 29 Jul 2008
Posts: 23
01-08-2009 14:06
Nvm, dumb question; I just disabled rotation :\

Anyway, It'll wiggle, but that's it.
_____________________
Error 407: Unhandled exception in Galaxy 9.
Reboot Universe? Y/N
JustinMichael Torok
Old builder, new scripter
Join date: 29 Jul 2008
Posts: 23
01-08-2009 15:37
I made some improvements to the script, but I hit a problem. I'm trying to use the llTarget function to determine when the elevator reaches the right floor. The at_target state doesn't seem to get raised, however. Anyone see a problem with this code?

CODE


vector position; //Base Position
integer targetID;
vector first;
vector second;
vector third;
vector roof;
vector call;
default
{
state_entry()
{
position = llGetPos();
llListen(13,"","","");
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE); //Disable rotation
llSetStatus(STATUS_BLOCK_GRAB|STATUS_PHYSICS, TRUE); //Disable grab
}

listen(integer channel, string name, key id, string message)
{
if(llVecDist(position, llGetPos()) <= 1)
{
second = llGetPos() + <0, 0, 8>;
third = llGetPos() + <0, 0, 16>;
roof = llGetPos() + <0, 0, 24>;
if(message == "first")
{
llWhisper(0, "First Floor.");
llSay(13, "Arrive");
}
else if(message=="second")
{
targetID = llTarget(second, 0.1);
llMoveToTarget(second, 1.5);
llWhisper(0, "Second Floor.");
}
else if(message == "third")
{
targetID = llTarget(third, 0.1);
llMoveToTarget(third, 1.5);
llWhisper(0, "Third Floor.");
}
else if(message == "roof")
{
targetID = llTarget(roof, 0.1);
llMoveToTarget(roof, 1.5);
llWhisper(0, "Roof.");
}
else
{
call = (vector)message;
targetID = llTarget(call, 0.1);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
}
}
else if(llVecDist(position, llGetPos()) <= 9)
{
first = llGetPos() - <0, 0, 8>;
third = llGetPos() + <0, 0, 8>;
roof = llGetPos() + <0, 0, 16>;
if(message == "first")
{
targetID = llTarget(first, 0.1);
llMoveToTarget(first, 1.5);
llWhisper(0, "First Floor.");
}
if(message == "second")
{
llWhisper(0, "Second Floor.");
llSay(13, "Arrive");
}
if(message == "third")
{
targetID = llTarget(third, 0.1);
llMoveToTarget(third, 1.5);
llWhisper(0, "Third Floor.");
}
if(message == "roof")
{
targetID = llTarget(roof, 0.1);
llMoveToTarget(roof, 1.5);
llWhisper(0, "Roof.");
}
else
{
call = (vector)message;
targetID = llTarget(call, 0.1);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
}
}
else if(llVecDist(position, llGetPos()) <= 17)
{
first = llGetPos() - <0, 0, 16>;
second = llGetPos() - <0, 0, 8>;
roof = llGetPos() + <0, 0, 8>;
if(message == "first")
{
llMoveToTarget(first, 1.5);
llWhisper(0, "First Floor.");
}
if(message=="second")
{
llMoveToTarget(second, 1.5);
llWhisper(0, "Second Floor.");
}
if(message == "third")
{
llWhisper(0, "Third Floor.");
llSay(13, "Arrive");
}
if(message == "roof")
{
llMoveToTarget(roof, 1.5);
llWhisper(0, "Roof.");
}
else
{
call = (vector)message;
targetID = llTarget(call, 0.1);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
}
}
else if(llVecDist(position, llGetPos()) <= 25)
{
first = llGetPos() - <0, 0, 24>;
second = llGetPos() - <0, 0, 16>;
third = llGetPos() - <0, 0, 8>;
if(message == "first")
{
targetID = llTarget(first, 0.1);
llMoveToTarget(first, 1.5);
llWhisper(0, "First Floor.");
}
if(message=="second")
{
targetID = llTarget(second, 0.1);
llMoveToTarget(second, 1.5);
llWhisper(0, "Second Floor.");
}
if(message == "third")
{
targetID = llTarget(third, 0.1);
llMoveToTarget(third, 1.5);
llWhisper(0, "Third Floor.");
}
if(message == "roof")
{
llWhisper(0, "Roof.");
llSay(13, "Arrive");
}
else
{
call = (vector)message;
targetID = llTarget(call, 0.1);
llMoveToTarget((vector)message, 1.5);
llWhisper(0, "The elevator has arrived.");
}
}
}
at_target(integer tnum, vector targetpos, vector ourpos)
{
llSay(13, "Arrive");
llTargetRemove(targetID);
llStopMoveToTarget();
llSetStatus(STATUS_PHYSICS, FALSE);
}
}
_____________________
Error 407: Unhandled exception in Galaxy 9.
Reboot Universe? Y/N
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-08-2009 21:46
Let's see if we can make the code a little more generic, and reuse some of it. That should make it a lot simpler and easier to debug. For each floor you have an identifier, a name, and an offset from the object's initial position. That sounds like a list to me:

(NOTE: I haven't compiled or tested these changes, but hopefully they'll at least give you an idea of how you can reorganize things to simplify)
CODE

list DESTINATIONS =
[ "first", "First Floor", ZERO_VECTOR,
"second", "Second Floor", <0.0, 0.0, 8.0>,
"third", "Third Floor", <0.0, 0.0, 16.0>,
"roof", "Roof", <0.0, 0.0, 24.0> ];

// These are strides computed later to make the above more readable.
list DESTINATION_IDS;
list DESTINATION_NAMES;
list DESTINATION_OFFSETS;

float CLOSE_ENOUGH_DIST = 0.1;
float MOVE_DAMPING = 1.5;


vector position; //Base Position
integer targetID = 0;


integer initialized = FALSE;
init()
{
if (initialized)
{
return;
}
initialized = TRUE;

DESTINATION_IDS =
llList2ListStrided(DESTINATIONS, 0, -1, 2);
DESTINATION_NAMES =
llList2ListStrided(llDeleteSubList(DESTINATIONS, 0, 0), 0, -1, 2);
DESTINATION_OFFSETS =
llList2ListStrided(llDeleteSubList(DESTINATIONS, 0, 1), 0, -1, 2);
}

initializeMoveTo(vector pos)
{
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(pos, MOVE_DAMPING);
targetID = llTarget(pos, CLOSE_ENOUGH_DIST);
}

finalizeMove()
{
if (targetID != 0)
{
llTargetRemove(targetID);
targetID = 0;
}

llSetStatus(STATUS_PHYSICS, FALSE);
llStopMoveToTarget();

llWhisper(13, "Arrive");
}

initializeMoveToNamedPosition(string name)
{
integer destIndex = llListFindList(DESTINATION_IDS, [ name ]);

vector destination;
if (destIndex >= 0)
{
string name = llList2String(DESTINATION_NAMES, destIndex);
destination = position+llList2Vector(DESTINATION_OFFSETS, destIndex);
llWhisper(0, name+".");
} else
{
destination = (vector)name;
llWhisper(0, "The elevator is moving...");
}

vector currPos = llGetPos();
if (llVecDist(currPos, destination) > CLOSE_ENOUGH_DIST)
{
initializeMoveTo(destination);
} else
{
finalizeMove();
}
}


default
{
state_entry()
{
position = llGetPos();
llListen(13,"","","");
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE); //Disable rotation
llSetStatus(STATUS_BLOCK_GRAB, TRUE); //Disable grab
}

listen(integer channel, string name, key id, string message)
{
initializeMoveToNamedPosition(message);
}

at_target(integer tnum, vector targetpos, vector ourpos)
{
finalizeMove();
}
}
Geraldo Holgado
Registered User
Join date: 10 Feb 2007
Posts: 2
Compensate buoyancy
03-21-2009 10:04
Hello,

in a similar script I added the following line to the initialization code:

llSetBuoyancy(1); // compensate gravity

this compensates the gravity of the physical object. With this the elevator cabin hovers after been switched to physical. Without this the (upward) force of llMoveToTarget() would be probably too low to overcome the gravity force.

Regards
Geraldo