Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Movement trigger

Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
02-08-2006 23:13
Ok im making this script to make a particle effect to come on whenever this prim moves all I do is replace the llSay part with the particle but it the trigger dosent seem to be working it just continually says moved.
CODE

default
{
state_entry()
{
llSetTimerEvent(1);
}
timer()
{
vector last_pos;
{
if(last_pos != llGetPos())
{
llSay(0, "Moved");
}
else
{
}
}
last_pos = llGetPos();
}
}
Hugsy Penguin
Sky Junkie
Join date: 20 Jun 2005
Posts: 851
02-09-2006 00:30
The problem is that last_pos is a local variable to the timer event. It should be global. Also, you may want to change the comparison to use llVecDist since it's bad practice to compare floats:

CODE

vector last_pos;

default
{
state_entry()
{
llSetTimerEvent(1);
}

timer()
{
if(llVecDist(last_pos, llGetPos()) > 0.00001)
{
llSay(0, "Moved");
}
else
{
}
last_pos = llGetPos();
}
}
Tip Baker
Registered User
Join date: 12 Nov 2005
Posts: 100
02-09-2006 00:54
You could use llGetVel() function in your timer event.

http://secondlife.com/badgeo/wakka.php?wakka=llGetVel


Depending on your application you may be able to get rid of the timer event completely and use the moving_start event

http://secondlife.com/badgeo/wakka.php?wakka=moving_start
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
02-09-2006 02:41
From: Hugsy Penguin
Also, you may want to change the comparison to use llVecDist since it's bad practice to compare floats:
While I would normally agree, Hugsy, in this case I would stick to the comparison. If an object doesn't move, multiple calls to llGetPos will all return exactly the same values. They all contain the same "rounding errors" if you will.

Keno, consider Tip's moving_start suggestion - but if you do continue using a regular timer event note that llVecDist requires 3 float multiplies and a square root to calculate. Use comparison wherever you can - it's much faster.