Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Elevator Issues!

Enrique Plutonian
Registered User
Join date: 24 Nov 2008
Posts: 3
02-02-2009 09:31
I am designing an elevator with four floors. On the elevator, there is a button for each floor that the user touches to take them to that floor. The buttons and the elevator are all linked together and the floor of the elevator is the root prim. Here's the scripts I used:


For each button:

default
{
touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT, 0, "first", NULL_KEY);
}
}


(of course for the second floor button, I said "second" instead of "first", etc.)




For the elevator floor (root prim):

vector first = <86.387, 182.078, 29.301>;
vector second = <86.387, 182.078, 36.957>;
vector third = <86.387, 182.078, 47.777>;
vector fourth = <86.387, 182.078, 57.638>;
vector pos;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
pos = llGetPos();
if(str=="first";)
{
pos.z = first.z;
llSetPos(pos);
}
if(str=="second";)
{
pos.z = second.z;
llSetPos(pos);
}
if(str=="third";)
{
pos.z = third.z;
llSetPos(pos);
}
if(str=="fourth";)
{
pos.z = fourth.z;
llSetPos(pos);
}
}
}


(the vectors are the positions for the elevator for each floor)


The problem I was having was that no matter what button I clicked, the elevator would only move one floor at a time. For example, if I'm on first and I touch fourth, I move only to second. I have to touch it two more times to get to fourth.

My quick fix for this problem was to change the first and fourth floor buttons into down and up arrows (respectively), and that seems to work fine, but is there a way I can fix my script to use the four-button method I was looking for?


The elevator is here if you want to try it out for yourself:
http://slurl.com/secondlife/CIST%20Nebraska%20Omaha/86/181/31
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-02-2009 09:35
using llSetPos can only move up to 10 meters at a time so if your floors are more than 10 meters apart you might need to use a loop to get it to move there for a non-physical movement

edit: so currently with your vectors, it would appear to only move 1 floor at a time because the only ones that are less then 10 meters apart are first and second, and third and fourth. second and third are a little more than 10 meters so you might get odd results with that one
Enrique Plutonian
Registered User
Join date: 24 Nov 2008
Posts: 3
02-03-2009 14:53
Ha ha, what I ended up doing was putting llSetPos(pos); in there four times for each button! Works great too! Thanks!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-03-2009 16:04
It would really be nice if we had an option between physical and non-physical. Basically, a way of saying, "Outside forces and collisions should not affect this object's movement, but true physical objects may be affected normally by a collision with it and the physical movement functions applied from its scripts will affect it normally (internal forces)." While that would be just as much of a burden on the simulator as a physical object, it would allow us a smooth movement option without the fear of our object being launched into orbit or not being able to get through an opening that's just barely large enough or something.

What the heck: http://jira.secondlife.com/browse/SVC-3783
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-04-2009 05:38
i haven't tested this, but i at least checked it for syntax errors:

CODE

list floors =
["first",<86.387, 182.078, 29.301>,
"second",<86.387, 182.078, 36.957>,
"third",<86.387, 182.078, 47.777>,
"fourth",<86.387, 182.078, 57.638>];
float dist;
vector dest;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
integer i = llListFindList(floors,[str]);
if(i > -1){
dest = llList2Vector(floors,i+1);
dist = llVecDist(llGetPos(),dest);
while(dist > 0.0)
{
llSetPos(dest);
dist = llVecDist(llGetPos(),dest);
}
}
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-04-2009 08:38
From: Ruthven Willenov
i haven't tested this, but i at least checked it for syntax errors....

That script is a very good example of why you should ALWAYS use curly braces ({}) on your control structures. Notice the 'if' statement.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-04-2009 14:16
From: Hewee Zetkin
That script is a very good example of why you should ALWAYS use curly braces ({}) on your control structures. Notice the 'if' statement.


whoops, yep, i did the braces for the while loop, but forgot them for the if statement, thanks hewee. edited above