Difference between revisions of "User:Pete Olihenge"
Jump to navigation
Jump to search
(Created page with '== Random negative chat channel == This LSL code snippet should, according to my calculations, return a random negative integer in the range -2,000,000,000 to -1,000,000, suitab...') |
|||
Line 1: | Line 1: | ||
== Random negative chat channel == | == 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. | |||
This LSL | |||
<lsl> | <lsl> | ||
integer GetDialogChannel () | integer GetDialogChannel () | ||
{ | { | ||
return (integer) llFrand (-1999000001.0) - 1000000; | return (integer) llFrand (-1999000001.0) - 1000000; | ||
} | |||
</lsl> | |||
== Ordinal suffix == | |||
This LSL function takes an integer and retuens 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> | </lsl> |
Revision as of 04:52, 26 January 2010
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 retuens 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>