Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

The script repeats twice

Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
02-06-2007 09:19
Hi!

I've written a script that moves an object with a sitted avatar, I use it to go from first floor to second in my house. When the object brings me to the second floor (UnSit) it comes back to the first floor, and then this object makes the same run again, this time it goes alone from the first floor to second and then back to the first floor.

Do you know how can I avoid that it happens?. I only want that it brings me to the first floor and then it goes back to the first floor and waits there until someone sits on it.

Thank you.

This is the script.

CODE


// GLOBALES DE POSICION
vector salida = <14.618,147.5,93.348>;
vector medio = <11.553,147.5,99.029>;
vector destino = <9.491,147.5,98.402>;
// SCRIPT DE AZUL WILDER PARA MOVER COSAS CON AVATARES SENTADOS
// FUNCIONES GLOBALES PARA IR A LOS DISTINTOS DESTINOS
ir_medio()
{
llSleep(3);
llMoveToTarget(medio,0.2);
llSleep(1);
}
ir_destino()
{
llMoveToTarget(destino,0.2);
llSleep(0.5);
llSetStatus(STATUS_PHANTOM,TRUE); // ESTO EVITA QUE EL MUÑECO SE QUEDE DE PIE EN LA PLATAFORMA
key muneco = llAvatarOnSitTarget();
llUnSit(muneco);
llSleep(3);
}
ir_salida()
{
llSetStatus(STATUS_PHANTOM,FALSE);
llMoveToTarget(salida,0.2);
llStopMoveToTarget();
}

// COMIENZA EL SCRIPT

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS,TRUE);
// ESTO DA ESTABILIDAD AL DESPLAZAMIENTO
llSetStatus(STATUS_ROTATE_X,FALSE);
llSetStatus(STATUS_ROTATE_Y,FALSE);
llSetStatus(STATUS_ROTATE_Z,FALSE);

llSitTarget(<-.5,0,.5>,<0,0,90,1>);
llSetSitText("Subir");
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
ir_medio();
ir_destino();
ir_salida();
}
else
{
llOwnerSay("Parece que no hay muneco en la plataforma");
}
}
}


Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
02-06-2007 09:28
It's because a changed event with CHANGED_LINK happens when the avatar unsits as well as when they sit. Thus, when the avatar unsits, changed is run again. This change will prevent that:

CODE

if(change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() != NULL_KEY)
{
ir_medio();
ir_destino();
ir_salida();
}
}
else
{
llOwnerSay("Parece que no hay muneco en la plataforma");
}
}
}
Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
02-06-2007 10:13
Thanx Yumi, it has solved that problem. I didn't realize about the UnSit problem.

I have observed another strange behavior it is that the "seat" doesn't come back to the right initial coordinates. when it comes back to the starting position.

Do you know why?

Regards.
Dustin Widget
Script Monkey for hire
Join date: 15 Feb 2006
Posts: 101
02-06-2007 10:56
Physics are less of an exact math and more of a try and fix in sl. Make sure your ending coordinates are correct and try putting a small sleep after your last move, like so.

CODE


ir_salida()
{
llSetStatus(STATUS_PHANTOM,FALSE);
llMoveToTarget(salida,0.2);
llSleep(0.5);
llStopMoveToTarget();
}

Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
02-06-2007 11:20
Thanks Dustin;

I tried that and it has improved the behavior, but let my tell you something when I edit the object and change the position to the correct starting position and then I close the editing window, suddenly the object goes down in the z axis (closer to the floor). The problem now seems to be in that axis only the other two positions are correct. If I change it there is no change.

I don't know why it doesn't respect this coordinate in the global vector variable.
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
02-06-2007 11:49
The reason is that you're using llMoveToTarget. This tells the object to move to the appropriate location in a given about of time, but it doesn't wait for it to arrive! Thus the llStopMoveToTarget() command may cut it off in the middle.

The easiest way around this would be to make the object non-physical and use llSetPos instead.
Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
02-06-2007 12:18
You are right Yumi. It has solved the problem in full.

Thanks a lot. your help is very appreciated.