Difference between revisions of "User:Pete Olihenge"

From Second Life Wiki
Jump to navigation Jump to search
(Blanked the page)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
== LSL functions ==
 
=== Random negative chat channel ===
This LSL function should, according to my calculations, return a random negative integer in the range -2,000,000,000 to -1,000,000, suitable for use as a dialog chat channel.
<lsl>integer GetDialogChannel ()
{
    return (integer) llFrand (-1999000001.0) - 1000000;
}</lsl>
=== Ordinal suffix ===
This LSL function takes an integer and returns a string that is the integer with its ordinal suffix ("st", "nd", "rd" or "th") appended.
<lsl>string OrdinalSuffix (integer number)
{
    string result = "th"; //for all except 1s, 2s and 3s, but including 11, 12 and 13
    number = number % 100; //just the 10s
    if (number < 4 || number > 20) //exclude the teens (and their neighbours)
    {
        number = number % 10; //just the units
        if (number == 1) result = "st"; //*1st
        else if (number == 2) result = "nd"; //*2nd
        else if (number == 3) result = "rd"; //*3rd
    }
    return (string) number + result;
}</lsl>
=== Format a metric measure to Imperial (or US) units, with fractional inches ===
This LSL function takes a float value representing a measure in metres and returns a string representing the equivalent Imperial (or US) measure in feet and inches, rounded to the nearest quarter inch, and expressed using the feet and inches symbols ' and ", and the fractional characters ¼, ½ and ¾.
<lsl>string FormatImperial (float metres)
{
    string result = "";
    float inches = metres / 0.0254;
    integer whole_inches = (integer) (inches + 0.125);
    float part_inches = inches - (float) whole_inches;
    integer whole_feet = whole_inches / 12;
    whole_inches = whole_inches % 12;
    if (whole_feet) result += (string) whole_feet + "' ";
    if (whole_inches) result += (string) whole_inches;
    else if (part_inches < 0.125) result += "0";
    if (part_inches >= 0.625) result += "¾";
    else if (part_inches >= 0.375) result += "½";
    else if (part_inches >= 0.125) result += "¼";
    return result + "\"";
}</lsl>
=== Pluralise ===
This LSL function takes an integer and a string and returns a string that is the input string with a lower-case "S" appended if the integer is not equal to 1.
<lsl>string Pluralise (integer number, string word)
{
    if (number == 1) return word;
    else return word + "s";
}</lsl>
=== ToggleText ===
This LSL function takes a Boolean integer and two strings and returns the first string if the integer represets TURE and the second if not. This is useful for including things like status information in the text parameter of [[llDialog]].
<lsl>string ToggleText (integer test, string if_true, string if_false)
{
    if (test) return if_true;
    else return if_false;
}</lsl>

Latest revision as of 15:21, 1 April 2010