Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion Simple Elevator

Peter Linden
Registered User
Join date: 18 Nov 2002
Posts: 177
04-14-2003 14:25
Simple Elevator- moves up and down alot

Summary: The following script will make an elevator raise an lower constantly. To use, create any convincing elevator, attach this script. Type the word "align" then type "start" to start the elevator and "stop" to stop the elevator, then watch it rise and fall like the stock market.

Usage: This is a very basic elevator that merely goes up and down over and over.. My first usage of it was on a small platform. You can set the height by changing the "integer distance" number.

Script:
CODE

vector top;
vector bottom;
integer counter = 1;
integer distance = 10; //this is the distance between the top and bottom of the elevators movement.
float time = 7; //you will have to play with this value probably
default
{
state_entry()
{
key id = llGetOwner();
llListen(0,"",id,"");
llSetStatus(STATUS_ROTATE_X| STATUS_ROTATE_Y| STATUS_ROTATE_Z, FALSE);
}

listen(integer channel, string name, key id, string message)
{
if(message == "align") // the code that follows sets the two positions
that it will oscillate between.
{
bottom = llGetPos();
top = bottom + <0,0,distance>;
llSetStatus(STATUS_PHYSICS,TRUE);
llSleep(0.1);
llMoveToTarget(bottom, 0.1);
}
if(message == "start")
{
llSetTimerEvent(time);
}
if(message == "stop")
{
llSetTimerEvent(0);
}
}

timer()
{
if(counter > 0)
{
llMoveToTarget(bottom,2);
}
else
{
llMoveToTarget(top,2);
}
counter *= -1;
}
}

Notes: This elevator is is on a timer, but it could just as easily have been put into a for loop with a llSleep call. Feel free to make improvements and additions.


Credits:
Script written by:
Nada Epoch 3-20-03
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread:
04-25-2005 08:38
/15/31/1901/1.html
_____________________
i've got nothing. ;)
Mhaijik Guillaume
Chadeaux Vamp
Join date: 18 Jun 2004
Posts: 620
Lag question on this
07-20-2005 07:43
I really like this script. It does exactly what I want. My question is though, since it listens does this cause much lag ?

Could it be converted to 'touch' start and stop and have align happen on rez ?
Would that make it lag free ?
_____________________
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
07-20-2005 08:23
you can find better elevator scripts in SL. Remember this script is 2 years old
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Mhaijik Guillaume
Chadeaux Vamp
Join date: 18 Jun 2004
Posts: 620
to clarify
07-20-2005 09:18
Ok I will try and be a little more clear -


First - I do not want an elevator.
I want the behavior of this script - how it makes an object move is exactly like I want as well as how it looks moving. I can also control the speed and height.

I have been working on my idea for weeks now and have not found anything in SL . I can buy swings and elevators - but not see the code. I guess I need to visit the inworld library, (makes note to search 'script' tonight.)

I have looked in the WiKi - I have tried things from there, but the movement is not the' look' I want.

Hence my question here on this script and lag.

Thank you,
_____________________
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
07-20-2005 13:34
Isn't a huge resource hog, but it could be cleaned up easily.

I'd dump the listen and use Touch to toggle moving on/off. I'd do the aligning manually (although automated is nice). At least the listener is owner specific. One listener, imho, is not much burden, it's the crappy coded multi-listeners on chan 0 listening to everyone that suck resources.

The constant MoveToTarget (and listener) means this is an Active script, verses a Passive system (touch/collisions/etc). Stopping the MoveToTarget when the lift isn't in use would reduce a tad of burden.

Still, overall, it's a low burden system -- unless it's colliding with something :p It could be improved on, easily, though.

Bos
Lum Kuhr
Registered User
Join date: 29 Jun 2005
Posts: 93
07-24-2005 20:23
I've been playing with this script, still not used to LSL, but this has been handy.

I made a few modifications, set it to listen on channel 1, and took away the timer events, it now just listens for the words "up" or "down" on that channel and calls llMoveToTarget. I also hardcoded the top and bottom positions for my application.

What is this like in terms of server resources. I am assuming that because it's not on channel 0 then it wont be parsing everyone's text all the time and will therefore be efficient, also it's not moving unless someone wants it to.

I have a few questions though.

1) Is there something like llMoveToTarget that moves at a constant velocity as it's really weird the way it slows down and takes ages to do the last part of the move.
I worked around this by putting in a llSleep(4); then calling llMoveToTarget again with a much lower tau setting

2) When the lift is in the top position, for some reason avatars slowly slide in one direction despite the fact that rotation is unchanged, when it's at the bottom it works fine. Any idea how to fix this?

3) for some reason, the physical prim that makes up the list becomes phantom even though this is not set in either the script or the object properties

4) on a fast lift, the avatar goes flying off when it stops at the other end. This is a particular problem with my application as the direction of travel isn't just vertical

I worked around those last two by making a non-physical hollowed cube attached to the root prim to keep the avatars in place


Lastly and unrelated I suppose, my lift covers a distance of about 35 metres, so you cannot call it from the bottom if it's currently at the top. I made an invisible phantom prim half way up with a listen script that simply does llSay(1,"down";) if it hears someone say "bottom" and similar for calling it to the top. Surely there's a better way to do this?
Fox Stirling
Certified Lunatic
Join date: 16 Aug 2004
Posts: 120
07-25-2005 14:45
From: Lum Kuhr

Lastly and unrelated I suppose, my lift covers a distance of about 35 metres, so you cannot call it from the bottom if it's currently at the top. I made an invisible phantom prim half way up with a listen script that simply does llSay(1,"down";) if it hears someone say "bottom" and similar for calling it to the top. Surely there's a better way to do this?



llShout(1,"down";);

:D
_____________________
...
Lum Kuhr
Registered User
Join date: 29 Jun 2005
Posts: 93
07-26-2005 09:15
There is only one repeater, so llSsay can get the lift regardless of position.

I was thinking more of doing it with less listen scripts needed, since there are now two listeners and I keep hearing about how they are a bad thing.

Or are listeners the correct way to acheive communication between objects, and it's just listeners on channel 0 that cause problems?

Edit: I suppose with llShout I could put a listener (or button) in the base that responds to the call command by shoting to the lift what floor it needs to be on, then have the lift only listen to local commands.

Ideally I would then have some way for the lift to detect that an avatar is inside and ignore any call command that would reverse it's direction.

This could be an interesting project if multiple floors are to be acheived. I can see how to do everything except get a smooth, constant rate of movement. If someone can tell me how to do that, I promise to post the finished result here. :)

(I can't do anything now until Friday as I'm no-where near a computer capable of running SL until then)
Milkbone Albion
Registered User
Join date: 24 Jul 2005
Posts: 22
My elevator problems
08-15-2005 14:03
Every time I try to make an elevator, the elevator moves, but I don't. So it will go down and I stay up there.. then I fall when I click again. My latest one uses MoveToTarget and turns on the physics.. but it never goes up.. All that happens is that it turns on physics and then it falls. It is a linked object, with a floor, a bar sticking up with two buttons on it.

http://www.michaelsmith.tv/forumposts/milkbone_elevator.jpg

The buttons light up when pushed (by offsetting the texture), and then they send a message to the floor the elevator floor via llMessageLinked. Then the floor gets the message, moves to that level, and then sends a message back to turn the button light off.

At least that's what I want it to do. My code has many things wrong with it, which I will fix with trial and error, but the main question I have is, does this work to move a person? It seems like the floor moves and I don't move with it.


Here's all my code:

Elevator Floor:

CODE


// lowerlevel = 36.1
// upperlevel = 42.57
integer targetID;

default
{
state_entry()
{
// This is linked object #4
}
link_message(integer sender_num,integer floor,string str,key id)
{
if (floor = 1)
{
llSay(0,"moving to 1");
llSetStatus(STATUS_PHYSICS, TRUE);
vector destination = <25.85,62.6,36.1>;
float range = 0.5;
targetID=llTarget(destination,range);
llMoveToTarget(destination,5);
}
else if (floor = 2)
{
llSay(0,"moving to 2");
llSetStatus(STATUS_PHYSICS, TRUE);
vector destination = <25.85,62.6,42.57>;
float range = 0.5;
targetID=llTarget(destination,range);
llMoveToTarget(destination,5);
}
}
not_at_target()
{
llSetRot(ZERO_ROTATION);
}
at_target( integer number, vector targetpos, vector ourpos)
{
llSay(0,"at target");
llTargetRemove(targetID);
llStopMoveToTarget();
llSetStatus(STATUS_PHYSICS,FALSE);
llMessageLinked(LINK_SET,0,"","");
}

}


Button for level 2:

CODE

default
{
state_entry()
{
// This is linked object #1
}

touch_start(integer total_number)
{
llSay(0, "2nd Floor Button Pushed");
llOffsetTexture(0.25,0.75,1);
llMessageLinked(LINK_SET,2,"","");
llSay(0,(string)llGetLinkNumber());
}
link_message(integer sender_num,integer num,string str,key id)
{
if (sender_num = 4)
{
llOffsetTexture(.25,.25,1);
}
}

}


Button for level 1:

CODE

default
{
state_entry()
{
// This is linked object #2
}

touch_start(integer total_number)
{
llSay(0, "1st Floor Button Pushed");
llOffsetTexture(0.75,0.75,1);
llMessageLinked(LINK_SET,1,"","");
llSay(0,(string)llGetLinkNumber());
}

link_message(integer sender_num,integer num,string str,key id)
{
if (sender_num = 4)
{
llOffsetTexture(.75,.25,1);
}
}
}


The other thing I noticed.. is that when I touch any part of the elevator, it runs the Button 2 script. It that because of the order in which I clicked things as I grouped them? Should I have a NUL script in each of the other objects so that touching them doesn't run the Button 2 Script? The Button 1 does run the button 1 script.

Any ideas are welcome.. please feel free to copy my code, although it obviously doesn't work yet.

-Milkbone
Milkbone Albion
Registered User
Join date: 24 Jul 2005
Posts: 22
more focused elevator question
08-16-2005 03:25
Ok.. well, I've already found one problem in my code. I was using "=" instead of "==". Which explains why the down button code never executed.

BUT other than scripting help, I guess my main question was really:

How do elevators work in SL? When my script lowers the floor, the "passenger" doesn't move with it. Standing on an object that moves is not the same as sitting on an object that moves. And all the script examples I've seen use llMoveToTarget to move the platform, but does that really work to move a passenger?

To be fair, it's possible that my code wasn't even working well enough to actually move the platform, and that it was just lowering because the physics got turned on and it fell. But shouldn't the passenger fall with it?

-milkbone
Blain Candour
Registered User
Join date: 17 Jun 2005
Posts: 83
08-16-2005 03:53
Physics is not checked on your avatar again until you move. So if you stand on a prim and then delete it you will just float in mid air until you move. It is kind of like the old cartoons. You don't fall until you look down so to speak. This is because second life doesn't waste resources calculating for something that hasn't moved or been pushed at all. Keep in mind if an elevator has a roof the roof will bump you on the way down and you should fall. I haven't really messed with elevators much. I can fly after all.
Lum Kuhr
Registered User
Join date: 29 Jun 2005
Posts: 93
08-16-2005 16:32
Blain is correct here. Mine has an invisible prim as it's roof. Be careful that the prim does not get in the way of the floor buttons from a normal camera angle though!

I can confirm that elevators do work, although it looks a bit messy. They have a tendency to make your avatar do run animations and other silliness, and if they go too fast then you need that invisible prim to catch them before they go shooting off into the sky.

I'm working on the smooth movement thing with some degree of success. It's very hard to do, and I'm hoping to sell the finished result. I already have a nice simple(ish) interface for configuring where the floors are.
Milkbone Albion
Registered User
Join date: 24 Jul 2005
Posts: 22
08-16-2005 18:51
Ok, I get the stand and fall thing now.. so then I considered an idea where you "Sit" on the elevator floor (thereby attaching you to it) but using a custom "standing, waiting in elevator" animation as the sit animation. Then releasing the sit (standing) once you've arrived. But I'm new enough to SL that some of the paradigms haven't completely hit me yet. So I don't know if there is some reason that would not work, or would not be the best. For example, the user would have to hit the stand up button and then the avitar would maybe 'jump' and that wouldn't look good either.

I'm an old timer programmer (from the 80's - crap I'm old!), so the coding stuff I can usualy figure out on my own eventually via trial and error. But some of the SL specific stuff I look at and think, "why can't it be done this simple way or that simple way". It seems there's more to learn than just the LSL, there's a set of SL world rules that have to be understood as well.. Like the "avitar not physical until a move" type of things that I don't know to consider.
Agatha Palmerstone
Space Girl
Join date: 23 Jan 2005
Posts: 185
08-17-2005 15:49
From: Milkbone Albion
I'm an old timer programmer (from the 80's - crap I'm old!), so the coding stuff I can usualy figure out on my own eventually via trial and error. But some of the SL specific stuff I look at and think, "why can't it be done this simple way or that simple way". It seems there's more to learn than just the LSL, there's a set of SL world rules that have to be understood as well.. Like the "avitar not physical until a move" type of things that I don't know to consider.


hear hear!
_____________________
"Those who insist that objects, activities, people or creations have objective value are unhappy jealous souls who see all human commerce as a form of exploitation in which one party must always be cheated and degraded."

- Allan Thornton
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Need help with Simple Elevator
11-15-2005 06:57
I need help. I am trying to learn scripting by using and modifying existing scripts. I found the script for the simple elevator which posted a couple of years ago. It look like it would be perfict for my new home. Build a small platform and attached the scipt, but nothing happened. I have looked over the script, but and to slow to figure out what I am doing wrong. Would someone be kind and help me out. Not just fix it by help me understand what I am missing

Thanks
Lum Kuhr
Registered User
Join date: 29 Jun 2005
Posts: 93
11-15-2005 08:59
From: Mod Faulkner
I need help. I am trying to learn scripting by using and modifying existing scripts. I found the script for the simple elevator which posted a couple of years ago. It look like it would be perfict for my new home. Build a small platform and attached the scipt, but nothing happened. I have looked over the script, but and to slow to figure out what I am doing wrong. Would someone be kind and help me out. Not just fix it by help me understand what I am missing

Thanks


Have you enabled physics on the object properties tab?
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Simple Elevator not working
11-15-2005 13:28
I checked the physics tab as you suggested and set it on. However, still no action.

Here is the script as it is in the prim I am trying to use as the elevator

============================================================
vector top;
vector bottom;
integer counter = 1;
integer distance = 10; //this is the distance between the top and bottom
float time = 7; //you will have to play with this value probably
default
{
state_entry()
{
key id = llGetOwner();
llListen(0,"",id,"";);
llSetStatus(STATUS_ROTATE_X| STATUS_ROTATE_Y| STATUS_ROTATE_Z, FALSE);
}

listen(integer channel, string name, key id, string message)
{
if(message == "align";) // the code that follows sets the two positio

that it will oscillate between.
{
bottom = llGetPos();
top = bottom + <0,0,distance>;
llSetStatus(STATUS_PHYSICS,TRUE);
llSleep(0.1);
llMoveToTarget(bottom, 0.1);
}
if(message == "start";)
{
llSetTimerEvent(time);
}
if(message == "stop";)
{
llSetTimerEvent(0);
}
}

timer()
{
if(counter > 0)
{
llMoveToTarget(bottom,2);
}
else
{
llMoveToTarget(top,2);
}
counter *= -1;
}
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This should be almost identical to the original. Is there any value that I am suppose to insert? I use chat to say "align", then, "start". The prim lists me a owner.

Thanks

MOD