Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

What is wrong with this script? – Basic: Planer four direction moments in set area

Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
01-20-2009 20:00
Despite my efforts, I cannot get a prim to stay within a square of 10x10m. If anyone can point out my mistakes, which I am sure there are quite a few, I would greatly appreciate it. The script is working sort of. It just does not want to stay within the area I want it to. >_<


CODE

vector startingpos;
float momentplus = 1.00;
float momentneg = -1.00;
float maxXneg ;
float maxXplus ;
float maxYneg ;
float maxYplus ;
integer range = 5; // 5x2=10 Range Starting in Center so 5m each way!!!
integer delay = 2;
vector currentpos;

integer Random;

WEST()
{
llSetPos(llGetPos() + <momentneg,0.0,0.0>);

}

NORTH()
{
llSetPos(llGetPos() + <0.0,momentplus,0.0>);
}

EAST()
{
llSetPos(llGetPos() + <momentplus,0.0,0.0>);
}

SOUTH()
{
llSetPos(llGetPos() + <0.0,momentneg,0.0>);
}

default
{
state_entry()
{
}
//on_rez(integer start_param)
touch_start(integer total_number)
{

startingpos = llGetPos();
maxXneg = startingpos.x - range;//Moving WEST
maxXplus = startingpos.x + range;//Moving EAST
maxYneg = startingpos.y - range;//Moving SOUTH
maxYplus = startingpos.y + range;//Moving NORTH
@loop1;
currentpos = llGetPos();
Random = (integer)llFrand(4.0)+1;
llSleep(delay);



if (Random==1 && (currentpos.x+momentneg)>= maxXneg)
{
WEST();//(-)x
}
if (Random==1 && (currentpos.x+momentneg)< maxXneg)
{
EAST();
}


if (Random==2 && (currentpos.y+momentplus) <= maxYplus)
{
NORTH();//(+)y
}
if (Random==2 && (currentpos.y+momentplus) > maxYplus)
{
SOUTH();
}



if (Random==3 && (currentpos.x+momentplus) >= maxXplus)
{
EAST();//(+)x
}
if (Random==3 && (currentpos.x+momentplus) < maxXplus)
{
WEST();
}


if (Random==4 && (currentpos.y+momentneg) <= maxYneg)
{
SOUTH();//(-)y
}
if (Random==4 && (currentpos.y+momentneg) > maxYneg)
{
NORTH();
}

jump loop1;
}
}


arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-21-2009 01:57
This should do it.

if (Random==1 && (currentpos.x+momentneg) >= maxXneg)
{
WEST();//(-)x
}
if (Random==1 && (currentpos.x+momentneg) < maxXneg)
{
EAST();
}


if (Random==2 && (currentpos.y+momentplus) < maxYplus)
{
NORTH();//(+)y
}
if (Random==2 && (currentpos.y+momentplus) >= maxYplus)
{
SOUTH();
}



if (Random==3 && (currentpos.x+momentplus) < maxXplus)
{
EAST();//(+)x
}
if (Random==3 && (currentpos.x+momentplus) >= maxXplus)
{
WEST();
}


if (Random==4 && (currentpos.y+momentneg) >= maxYneg)
{
SOUTH();//(-)y
}
if (Random==4 && (currentpos.y+momentneg) < maxYneg)
{
NORTH();
}
Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
01-21-2009 04:05
Thank you arton Rotaru! It works perfect now. ^.=.^ Everyone in SL is so helpful and nice! :)