Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting a Reset on llGetPos

Alazar Fauna
Registered User
Join date: 27 Feb 2004
Posts: 2
01-27-2006 11:41
Hi.

Sorry for this super newb question but...

Im trying to do a really simple little movement script on a timer.

And I pretty much have it done....except...

The darn thing keeps moving to the point where it first rezzed..and I cant just drop it and make it start from there. Im trying to use llGetPos to do thisby reseting the script on_rez but that doesnt seem to be doing it.

Im sure this is really dumb of me..but any help would be appreciate.
CODE

vector prim_offset = <0,0,1>; // distance to move from start popsition(step1) to step2.
float steps = 10.0; // number of steps to move the prim to location

// Variables
vector step1;
vector step2;

// Functions
moveit(vector target)
{
vector offset = (target - llGetPos()) / steps;
while ( llVecDist(llGetPos(), target) > 0.1 )
{
llSetPos(llGetPos() + offset);
}
llSetPos(target);
}

// States

default
{
on_rez(integer n)
{
llResetScript();
}

state_entry()
{
llSetTimerEvent(5);
step1 = llGetPos();
step2 = (step1 + prim_offset);
llSay(0, "Ready!"); //debug
state one;
}
}

state one
{
timer()
{
moveit(step1);
llSay(0, "Step1"); //debug
state two;
}

}

state two
{
timer()
{
moveit(step2);
llSay(0, "Step2"); //debug
state one;
}

}


Thanks in advance. Ill try to learn quicker. :)
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
01-27-2006 12:16
When the script starts for the first time, it sets step1 to it's current position. It then immediately moves to state one. If you now take it back into inventory and rez it again, it's in state one or two (depending on when you took it into inventory), which don't have on_rez handlers, so step1 never gets updated, it stays set to the location where the script first started running.

So you need on_rez handlers in states one and two. You could llResetScript() in there, that would be one way to handle this. Or you could try setting step1 in there too. Either way, if your script is in the middle of executing moveit(), then the on_rez event won't be picked up until moveit() completes, so you could still get some strange movement. Try it out :)

Another way around it is to have the movement start on touch, so take the code in the state_entry for the default state, and put it into a touch_start handler. Maybe set text and/or set touch text as well so people know that they need to touch it to get it moving. This gives you a script that sits idle until it's touched, which makes it easier to saver that object (with the script in that state) back into inventory, and have it behave in a predictable way when it's rezzed again. Remember that a running script is 'frozen in time' when it's in inventory, and picks up again from where it left off when it's re-rezzed.
Damien Took
Meat Popsicle
Join date: 3 Dec 2004
Posts: 151
01-27-2006 12:24
Alazar,

I'm not sure why you are switching states but it looks like that, you could have used a flag in the timer but if this works then go with it.
Every time you go back to state one you are telling it to move back to the original location because you never set step1 to the new position.
This looks a bit more complicated than it has to be but I don't know your end goal.
Give this a try first though:

CODE
state one 
{
timer()
{
moveit(step1);
step1 = llGetPos();
llSay(0, "Step1"); //debug
state two;
}

}
Alazar Fauna
Registered User
Join date: 27 Feb 2004
Posts: 2
Yup :)
01-27-2006 12:56
Ok ...I didnt know about the 'memory' between states..thought a reset would handle that.

Argh...:)

The touch_start event is perfect. and lined it right up with its on_touch starting position...

Thanks !