Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help with else if in a timer event

Monique Binstok
Registered User
Join date: 5 May 2008
Posts: 87
10-20-2009 15:37
I made an airmattress that I'm trying to move back and forth between to positions using a timer event and changing the vector offset in llMoveToTarget. I added a few llSay for debuging. The script complies ok and when started the airmattress makes a few initial movements than holds at one positon. In chat I'll see "bottom" "first stop" repeated without ever seeing "second stop". Can someone tell what I have messed up and why the "else if" part of the timer event doesn't seem to be executing? Please bare in mind that I'm real new to scripting and any help if greatly appreicated.


CODE

vector offsetA =<-3,0,0>;
vector offsetB =<-7,0,0>;
string test = "";


default
{
state_entry()
{
test="top";
vector pos = llGetPos();
llSetStatus(STATUS_PHYSICS, TRUE);
llSetBuoyancy(1.0);
llSleep(0.1);
llSetTimerEvent(10.0);
}
timer()
{
llSay(0,test); //added for debug
if (test = "top")
{
test = "bottom";
llSay(0,"first stop"); //added for debug
vector pos = llDetectedPos(0);
(pos+= offsetB);
llMoveToTarget(pos,2.4);
}

else if (test = "bottom")
{
test = "top";
llSay(0,"second stop"); //added for debug
vector pos = llDetectedPos(0);
(pos+= offsetA);
llMoveToTarget(pos,2.4);

}
}

}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
10-20-2009 15:44
that's because in the if test you are declaring test to "top" again

if(test = "top";) should be
if(test == "top";)

likewise with the bottom test
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Pete Littlebird
Registered User
Join date: 30 Sep 2009
Posts: 44
10-20-2009 15:47
You are using the assignment "=" in the if tests: you should be using the comparator "==". Also, you should be using llGetPos () to determine the object's current position and not llDetectedPos (0), which only works with some events, and timer is not one of them.
Monique Binstok
Registered User
Join date: 5 May 2008
Posts: 87
10-20-2009 16:00
Thanks very much for the quick replies. I know it was prob something fairly basic :)