Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with User Defined Function in a Loop

Kristy Flanagan
Registered User
Join date: 7 May 2007
Posts: 2
06-18-2007 13:53
Hi,

The following code moves an object around in a square.
However, if I move the exact code in the loop to a makeSquare function and just call the function each iteration, the object just rotates about the z-axis and does not move forward.
Any ideas why? Working and non-working code snippets are below.
Thanks!

This works:
if( command == "square";)
{
integer i;
for( i = 0; i < 4; i++)
{
radians = g_angle * PI / 180;
y_Dist = llSin(radians) * distance;
x_Dist = llCos(radians) * distance;
llSetPos( llGetPos() + < x_Dist, y_Dist, 0 > );

g_angle = g_angle + 90;
rAngle = llEuler2Rot( < 0, 0, 90 * DEG_TO_RAD * 1 >;);
newRotation = llGetRot() * rAngle;
llSetRot( newRotation );
}

}

This doesn't work:

makeSquare()
{
radians = g_angle * PI / 180;
y_Dist = llSin(radians) * distance;
x_Dist = llCos(radians) * distance;
llSetPos( llGetPos() + < x_Dist, y_Dist, 0 > );

g_angle = g_angle + 90;
rAngle = llEuler2Rot( < 0, 0, 90 * DEG_TO_RAD * 1 >;);
newRotation = llGetRot() * rAngle;
llSetRot( newRotation );

}

if( command == "square";)
{
integer i;
for( i = 0; i < 4; i++)
{
makeSquare();
}

}
Kristy Flanagan
Registered User
Join date: 7 May 2007
Posts: 2
Never Mind
06-18-2007 14:14
I figured it out.

Thanks!