Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

issues with a script

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
10-25-2008 07:31
im getting sytax errors at this one point and cant seam to figure it out help will be greatfull

CODE

key lastSensed;
string display;
string lastSpeed;
string n1 = "";
string n2 = "";
string gsHexChars = "0123456789ABCDEF";
string Int2Hex(integer iInt)
{
integer iWork = iInt & 0xF;
string sResult = llGetSubString(gsHexChars, iWork, iWork);
iInt = (iInt >> 4) & 0x0FFFFFFF;

while (iInt != 0)
{
iWork = iInt & 0xF;
sResult = llGetSubString(gsHexChars, iWork, iWork) + sResult;
iInt = iInt >> 4;
}

return(sResult);
} // string Int2Hex


string Round2String(float fValue, integer iDecimals)
{
integer iValue = (integer)fValue;
integer iRemainder = llRound((fValue - iValue) * llPow(10, iDecimals));

if (!iRemainder)
{
return (string)iValue + ".00";
}
else
{
return (string)iValue + "." +(string)llAbs(iRemainder);
}

} // Round2String


string Vector2String(vector vVector, integer iDecimals)
{
return("<" + Round2String(vVector.x, iDecimals) + ", " +
Round2String(vVector.y, iDecimals)+ ", " +
Round2String(vVector.z, iDecimals) + ">");
} // Vector2String


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

state_entry()
{
llSensorRepeat("", "", AGENT, 10.0, PI/4, 1);
}
sensor(integer num_detected)
{
string speed = Round2String(llVecMag(llDetectedVel(0)), 2);
integer decimalIndex = llSubStringIndex(speed, "");
speed = llGetSubString(speed, 0, decimalIndex );
integer newSpeed = (lastSpeed != speed);
if(speed > 10) // ERROR!
{
llWhisper(0,"0"+speed);
}
else if(speed < 10) // ERROR!
{
llSetText(llDetectedName(0) + " is moving at " + speed + "m/s.",<1,1,1>,1);
lastSpeed = speed;
}
}
no_sensor()
{
llSetText("",<1,1,1>,1);
}
}
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
10-25-2008 07:37
You're getting syntax errors because "speed" is a string, but you're trying to use it like a number. The quickest solution is probably to declare it as a float, and then cast the result of the relevant functions to match, e.g. like this:

float speed = (float)Round2String(llVecMag(llDetectedVel(0)), 2);

Of course, then you'll need to cast the speed to a string when you want to output it in llWhisper or whatever.