Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with while loop

Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
10-09-2007 10:08
I am trying to create a function which moves a vehicle type object upwards on command to a certain height. I figured a while loop might be the best way to go about this so this is what I came up with
CODE


if (message == "surface")
{
float surface = llWater();
vector here = llGetPos();

while (here.z <= surface)
{
llSetStatus(STATUS_PHYSICS, TRUE);
llSetVehicleVectorParam (VEHICLE_LINEAR_MOTOR_DIRECTION ,<0,0,10>);//move up
}
llApplyImpulse(-llGetVel() * llGetMass(),FALSE);//counteract movement
llSetStatus(STATUS_PHYSICS, FALSE);//disable physics to stay put
}



in my mind this should cause the vehicle to rise up to water level and then stop and turn non physical. Am I mising something or is there a better way to achieve this result. I want it to only happen when the user commands it (will eventually go in a dialogue menu).

The listen section is already implemented within the script using som eif statements to pull out other commands.

I thought this would slot straight in but things aren't working as I would expect. I have tried a few variations of this and it seems to either make the object go up forever or it sits in place.
_____________________
Tread softly upon the Earth for you walk on my face.
Okiphia Rayna
DemonEye Benefactor
Join date: 22 Sep 2007
Posts: 2,103
10-09-2007 10:14
you could just use a touch command to set it to +x amount of meters...

off the top of my head, the one I used is using the llSetTargetPos((GetTargetPos +<0,0,50>;);

or something similar..that doesnt seem right... but you could set that, so that on rez the object only uses one touch, then goes to that height and changes state, then in the new state, touch wouldn't do anything. Unless you want it to be able to continue up at that set distance for each touch, then no state change is needed.

Wait, sorry, vehicle, dunno if it works then... sorry I forgot about that... I have no experience with vehicles =(
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-09-2007 10:19
Nothing in the while loop changes the here.z or surface values - once you get into this, you'll never get out. Water probably won't change but you need to update 'here'.

If you did this...

CODE

float surface = llWater();
vector here = llGetPos();

while (here.z <= surface)
{
llSetStatus(STATUS_PHYSICS, TRUE);
llSetVehicleVectorParam (VEHICLE_LINEAR_MOTOR_DIRECTION ,<0,0,10>);//move up
here = llGetPos();
}


...it would be closer to what you're trying to do.

Not sure what you're doing is the right way to do things - you'll probably run through this loop 100 times before it has a chance to move - but I'll leave that to the vehicle people..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-09-2007 10:21
Take a look here:

/54/ca/210616/1.html
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
10-09-2007 10:32
Thanks guys.

As Meade pointed out I am not updating the "here" position so the vehicle never new when it got above surface level. That makse sense as to why it just continued to rise when it was doing anything.

I shall try updating the script with a here=llGetPos(); once i get home from work.

I realise a while loop may not be the most elegant way to achieve what I'm going for but as the rest of the script is pretty cumbersome (and mostly not mine) I just wanted a small section of code to achieve this.

Maybe if I make it clearer what I'm doing that'll help.

Basically I'm making a submarine type vehicle. I got the behaviors to keep it under water while flying it but wanted to implement a "surface" command to get people up easily and stop the vehicle at surface level.
_____________________
Tread softly upon the Earth for you walk on my face.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-09-2007 10:45
I'd at least stick in a small delay then. Maybe a llSleep (0.5) before you reset 'here' at the bottom of the loop.

You also don't need to be turning physics on in the loop. Turning it on before then loop the off after the loop may be a bit less laggy.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
10-09-2007 10:50
ahh ok. Good catch Meade. You're my new hero :)
_____________________
Tread softly upon the Earth for you walk on my face.