Difference between revisions of "Meter2Feet"
Jump to navigation
Jump to search
Huney Jewell (talk | contribs) m |
Huney Jewell (talk | contribs) m (LSL highlighting) |
||
Line 12: | Line 12: | ||
== Specification == | == Specification == | ||
<div style="padding: 0.5em;"> | <div style="padding: 0.5em;"> | ||
< | <lsl> | ||
string Meter2Feet( float meter ) | string Meter2Feet( float meter ) | ||
{ | { | ||
Line 38: | Line 38: | ||
return (sign + (string)feet + "' " + (string)inches + strFraction); | return (sign + (string)feet + "' " + (string)inches + strFraction); | ||
} | } | ||
</ | </lsl> | ||
</div></div> | </div></div> | ||
Line 45: | Line 45: | ||
<div style="padding: 0.5em;"> | <div style="padding: 0.5em;"> | ||
Trivial example to listen to any chat from the object owner for '''{{LSL Param|meter}}''' values and respond feet/inch value. | Trivial example to listen to any chat from the object owner for '''{{LSL Param|meter}}''' values and respond feet/inch value. | ||
< | <lsl> | ||
// Insert code of Meter2Feet user function here | |||
default | default | ||
Line 85: | Line 62: | ||
llOwnerSay(Meter2Feet(meter)); | llOwnerSay(Meter2Feet(meter)); | ||
} | } | ||
}</ | }</lsl> | ||
</div></div> | </div></div> | ||
{{LSLC|Examples|Meter2Feet}} | {{LSLC|Examples|Meter2Feet}} |
Revision as of 03:15, 16 January 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Specification
<lsl> string Meter2Feet( float meter ) {
string sign = ""; if (meter < 0) { // Use only positive value to simplify the maths sign = "-"; meter = -meter; } // Compute feet multiplying by reciprocal value of // conversion constant 0.3048 for performance reasons float fraction = meter * 3.2808398950131233595800524934383; 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 != 0) // show fraction value only if not zero strFraction = " " + (string)((integer)fraction) + "/16" + strFraction;
return (sign + (string)feet + "' " + (string)inches + strFraction);
} </lsl>
Example
Trivial example to listen to any chat from the object owner for meter values and respond feet/inch value. <lsl> // Insert code of Meter2Feet user function here
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)); }
}</lsl>