Difference between revisions of "Meter2Feet"
Jump to navigation
Jump to search
m |
|||
Line 6: | Line 6: | ||
Returns a [[String|string]] of metric value '''{{LSL Param|meter}}''' converted to feet/inch in common representation, ie. 3' 4 5/16". | Returns a [[String|string]] of metric value '''{{LSL Param|meter}}''' converted to feet/inch in common representation, ie. 3' 4 5/16". | ||
{| | {| | ||
{{LSL DefineRow|[[float]]|meter|{{#var: | {{LSL DefineRow|[[float]]|meter|{{#var:p_meter_desc}}}} | ||
|} | |} | ||
</div></div> | </div></div> | ||
Line 47: | Line 47: | ||
fraction = llRound((fraction - inches) * 16); // Compute 1/16 inches | fraction = llRound((fraction - inches) * 16); // Compute 1/16 inches | ||
string strFraction = | string strFraction = ""; | ||
if (fraction | if (fraction) // show fraction value only if not zero | ||
strFraction = " " + (string)llAbs((integer)fraction) + "/16 | strFraction = " " + (string)llAbs((integer)fraction) + "/16"; | ||
return ((string)feet + "' " + (string)llAbs(inches) + strFraction); | return ((string)feet + "' " + (string)llAbs(inches) + strFraction+ "\""); | ||
} | } | ||
Revision as of 07:12, 12 September 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Specification
string Meter2Feet( float meter ) { float fraction = meter / 0.3047999984375; // Compute feet integer feet = (integer)fraction; fraction = (fraction - feet) * 12; // Compute inches integer inches = (integer)fraction; fraction = llRound((fraction - inches) * 16); // Compute 1/16 inches string strFraction = ""; if (fraction) // show fraction value only if not zero strFraction = " " + (string)llAbs((integer)fraction) + "/16"; return ((string)feet + "' " + (string)llAbs(inches) + strFraction+ "\""); }
Example
Trivial example to listen to any chat from the object owner for meter values and respond feet/inch value.
string Meter2Feet( float meter ) { float fraction = meter / 0.3047999984375; // Compute feet integer feet = (integer)fraction; fraction = (fraction - feet) * 12; // Compute inches integer inches = (integer)fraction; fraction = llRound((fraction - inches) * 16); // Compute 1/16 inches string strFraction = ""; if (fraction) // show fraction value only if not zero strFraction = " " + (string)llAbs((integer)fraction) + "/16"; return ((string)feet + "' " + (string)llAbs(inches) + strFraction+ "\""); } default { state_entry() { llOwnerSay("Enter: [m]"); llListen(0, "", llGetOwner(), ""); } listen(integer _chan, string _str, key _id, string _msg) { float meter = (float)_msg; llOwnerSay(Meter2Feet(meter)); } touch_start(integer n) { llOwnerSay( Meter2Feet( llVecDist( llGetPos(), llDetectedPos(0)))); } }