Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Speed Radar help

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
10-12-2008 13:46
im working on this one speed radar that will update a board but im having trouble asembling the string here is what im trying to do,

if you are under 10 m/s it will say the speed in 05 = 5 m/s ect
and if above it will have it as the 2 digits

im using substrings, any help will be appreciated

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)
{
if(llGetSubString(speed,0,2) == speed)
n1 = 0;
n2 = llDeleteSubString(speed, 0, 0);
display = n1+n2;
}
else if(speed < 10)
{
speed = display;
}
llSetText(llDetectedName(0) + " is moving at " + display + "m/s.",<1,1,1>,1);
llSay(-99,"number "+display);
lastSpeed = speed;
}
}
no_sensor()
{
llSetText("",<1,1,1>,1);
}
}
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
10-12-2008 13:52
Quick Observation

else if(speed < 10)
{
speed = display;
}

Should that not read display = speed;