Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Continuing problems

Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
01-18-2006 03:43
I put this originally in another thread, and a single poster helped me with an unrelated error, and as it meant I had to change the coding, I decided to start a new thread, in the hope that someone will be able to help.

The script concerned is an elevator program, and in essence it takes the following form:-

vector temp;
integer speed = 0;

move(integer speed);
{
temp=llGetPos()+<0.0,0.0,speed>;
llMoveToTarget(temp,0.1);
}


Listen on channel

Accept input

If command for elevator to ascend
Set non-physical
Position elevator platform
Set physical

while(temp.z < 747)
{
if(temp.z < 40)
{
move(1);
}

more stuff here if higher than 40

} end of while

} end of listen

What actually happens when the script is run is that the elevator ascends fine, with temp.z being incremented as it is supposed to be. Then the command to go down is given, and the program executes the second half, which brings it down again. The script then loops around the listen, waiting for input.

If an instruction to ascend is then given, what appears to happen is that temp.z in the move section becomes local. It is incremented within the move, but when execution goes back to the while it keeps the value it had before the call to move. And the elevator just sits there.


If anybody has any suggestions (apart from giving up scripting) I would be grateful.
_____________________
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
01-18-2006 04:06
A guess: Is the "Set non-physical - Position elevator platform - Set physical" definitely working correctly? The wiki says that there needs to be a 10cm seperation between an object and surrounding objects for the change to physics to work, but I've found in my elevator I had to go up to 12cm before I got 100% success.

If the change to physics fails, I would expect the symptoms you describe.

Other than that, I would suggest posting a more complete code snippet (if you don't mind others seeing it) - or add a whole lotta llOwnerSay statements in the code to keep you notified of where it's going and what values it's seeing, and post those results.

btw - you can post your code inside [PHP] and [/PHP] tags to keep it formatted.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
01-18-2006 04:21
Hi Sel, hope everything is OK apart from this headache.

Your code snippets make it hard to tell what's going on I'm afraid. For example you say (to paraphrase) set non-physical, position elevator, set physical but llMoveToTarget() seems to be your positioning call and that will only work on physical objects.

We're also lacking the logic parts for your code - likeliest single reason is something silly in an if statement, single = sign, < when you mean > etc. Oh, or a semi-colon on the end of the if line so it skips the next span always an easy mistake!

If checking all of those doesn't work I think you might have to bite the bullet and post the whole code.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-18-2006 05:28
This probably isn't really related to the bug, whatever it is, but... you're maintaining a global variable, temp, which you *think* is the position of the elevator, but you can't rely on that being true. You should have

temp = llGetPos();

before the "while" and before the "if" as well, to make sure that the position you're detecting is the right one, and don't use temp in the move() function, just have

llMoveToTarget(llGetPos() + <0,0,speed>, 0.1);

I think I'd use a timer and target event myself. I don't like that "while", it just seems wrong. Sorry. Nothing personal.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-18-2006 07:29
Anyway, I tried to make a board which you mentioned and script. As Eloise said, the most important point might be missed in your script. I managed to follow your script as much as possible. But I couldn't stand your speed value. And who said that llMoveToTarget would let objects move smoother!? :mad: :D Aha, and I used a touch method.
CODE
vector temp;
integer speed = 0;

vector StartPos; // For another trial to go move
integer TouchSW = FALSE; // Touch switch

move() // Never never never need any parameter here!
{
temp = llGetPos() +< 0.0,0.0,speed>;
llMoveToTarget(temp, 5); // You have to tweak this tau value.
}

default
{
state_entry()
{
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
StartPos = llGetPos();
}
on_rez(integer reset)
{
llResetScript();
}
touch_start(integer total_number)
{
if(!TouchSW)
{
llOwnerSay("Go up");
llSetStatus(STATUS_PHYSICS,TRUE);
while(temp.z < 747 + speed) // Consider why you need + speed here
{
if(temp.z < 40) // Sorry, I live in the place above 40m height :P
{
speed = 10; // I hate slow moving
move();
}
else if(temp.z > 720)
{
speed = 10;
move();
}
else
{
speed = 60; // Yay, faster!
move();
}
}
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llOwnerSay("Reached");
TouchSW = !TouchSW;
}
else
{
llOwnerSay("Go down");
llSetStatus(STATUS_PHYSICS,TRUE);
while(llVecDist(llGetPos(), StartPos) > 0.5)
{
if(temp.z > 700)
{
speed = -10;
move();
}
else if(temp.z < 40)
{
speed = -10;
move();
}
else
{
speed = -50;
move();
}
}
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llOwnerSay("Reached");
}
}
}
_____________________
:) Seagel Neville :)
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
01-18-2006 08:39
Ok, many thanks for the script. The problem I have is that I don't know how some of it works (I told you I was a rubbish scripter).

I have run the script, and will have to change it to accept verbal commands (which is what the first script did). So in a sense that makes this point invalid, but what happens is that when the elevator is touched after it has come down, instead of going up it continues to go down, buries itself in the ground, and then reappears where it was.

But thinking about it, that shouldn't be too difficult to fix, once the command line is changed.

The other thing is that it runs *very* slowly. The lift goes up at a snail's pace, despite the 'speed' variable being set high. I can't understand why. Is it something to do with the tau value? What is a tau value? What does it do?

Anyway, so long as I am able to speed it up, it is great that it runs slowly, because it will give me more flexibility when it comes to acceleration and deceleration. So long as I can get it to run fast when it needs to. :)

Many thanks for your help Seagel; it is much appreciated.
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-18-2006 09:10
From: Selador Cellardoor
I have run the script, and will have to change it to accept verbal commands (which is what the first script did). So in a sense that makes this point invalid
But if you used verbal commands, you could not use this method, couldn't you?. :o
CODE
while(temp.z < 747 + speed)     // Consider why you need + speed here
From: Selador Cellardoor
but what happens is that when the elevator is touched after it has come down, instead of going up it continues to go down, buries itself in the ground, and then reappears where it was.
Wow, sorry for that. I didn't think that. :D

Yup, tau value... sorry, I have to sleep. I hope someone would answer... zzz.
_____________________
:) Seagel Neville :)
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-18-2006 15:03
Aww... I've woke up. OK, I fixed the exploit and adopted your way.
CODE
vector temp; 
// integer speed = 0; Never never never use double same name of variable

vector StartPos; // For another trial to go move
integer TouchSW = FALSE; // Touch switch
integer is_moving = FALSE; // state of elevator

move(integer speed)
{
temp = llGetPos() +< 0.0,0.0,speed>;
llMoveToTarget(temp, 5); // You have to tweak this tau value.
}

default
{
state_entry()
{
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
StartPos = llGetPos();
}
on_rez(integer reset)
{
llResetScript();
}
touch_start(integer total_number)
{
if(is_moving == FALSE)
{
if(!TouchSW)
{
is_moving = TRUE;
llOwnerSay("Go up");
llSetStatus(STATUS_PHYSICS,TRUE);
while(temp.z < 747 + 10) // Consider why you need + 10 here
{
if(temp.z < 40) // Sorry, I live in the place above 40m height :P
{
move(10);
}
else if(temp.z > 720)
{
move(10);
}
else
{
move(60); // Yay, faster!
}
}
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llOwnerSay("Reached");
TouchSW = !TouchSW;
is_moving = FALSE;
}
else
{
is_moving = TRUE;
llOwnerSay("Go down");
llSetStatus(STATUS_PHYSICS,TRUE);
while(llVecDist(llGetPos(), StartPos) > 0.5)
{
if(temp.z > 700)
{
move(-10);
}
else if(temp.z < 40)
{
move(-10);
}
else
{
move(-50);
}
}
llSetStatus (STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llOwnerSay("Reached");
is_moving = FALSE;
}
}
else
{
llShout(0, "Don't touch me while moving!"); // Joke line
}
}
}
Sorry, I haven't tested above.

tau is Time at unit? It is how much time it takes by getting to the target.
So I believe that it is the same speed between llMoveToTarget(<0, 0, 10>, 2) and llMoveToTarget(0, 0, 1>, 0.2). ;)
In the same distance of target, decreasing the tau value, faster it would move. Oh, of course my comments are sometimes (always?) jokes. :cool:
_____________________
:) Seagel Neville :)
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
01-20-2006 05:32
Thanks Seagel,

Yes, the program has to accept voice input, which meant that I had to modify your script when I came to apply it to the elevator. Incidentally, the elevator has to mark its position when it gets to certain heights, and also has to play certain sounds, so it is quite a long script, about 400-odd lines in all.

I will make the modification you suggest, and try again.

Sorry you are being lumbered with all this effort. :)
_____________________
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
01-20-2006 05:40
From: Eloise Pasteur
Hi Sel, hope everything is OK apart from this headache.

Your code snippets make it hard to tell what's going on I'm afraid. For example you say (to paraphrase) set non-physical, position elevator, set physical but llMoveToTarget() seems to be your positioning call and that will only work on physical objects.

We're also lacking the logic parts for your code - likeliest single reason is something silly in an if statement, single = sign, < when you mean > etc. Oh, or a semi-colon on the end of the if line so it skips the next span always an easy mistake!

If checking all of those doesn't work I think you might have to bite the bullet and post the whole code.


Hi Eloise. :) Yes, I am fine thank you. Haven't been spending so much time in sl lately (apart from when I am struggling with scripts).

As I said to Seagel, unfortunately it's a big script. I'm sure it could have been written in a more economical way, but there do have to be checks and tests at various positions as the elevator ascends. As far as the llMoveToTarget goes, you can see from my example that physical has been set by the time the script starts using llMoveToTarget.

I don't think there are any (more) obvious syntax errors. I have been over the script with a fine tooth-comb. I know these things can always slip through, but it's been days now, and if it's not right from that point of view it never will be. :)

I will check out Seagel's version and see how that works when it comes to the crucial second ascent. So far I haven't reached that point. If it still doesn't work I'll post the entire code, but I don't think that will (a) please the Lindens or (b) make me respected as a scripter. :)
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-21-2006 11:06
From: Selador Cellardoor
Sorry you are being lumbered with all this effort. :)

No problem. That's my pleasure. But I found one thing. The tau is fixed and the z-axis length is flexible. So it might turn to be some uncomfortable values such as too fast or too slow in your undescribed script.
_____________________
:) Seagel Neville :)
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
01-23-2006 05:05
I am glad to say that the script is finally working! I am so delighted that I don't even worry about the fact that I don't know why the last one didn't.

Many thanks for everybody's help.

I still have one query, but I will save that for another thread. :)
_____________________