Difference between revisions of "Category:LSL Integer"
Omei Qunhua (talk | contribs) (More decimal string validations) |
Lady Sumoku (talk | contribs) m (Replaced old <LSL> block with <source lang="lsl2">) |
||
Line 9: | Line 9: | ||
==Examples== | ==Examples== | ||
All of the following are integers: | All of the following are integers: | ||
< | <source lang="lsl2">integer firstInt = 5512623; | ||
integer secondInt = ACTIVE; | integer secondInt = ACTIVE; | ||
integer thirdInt = 0x61EC1A; | integer thirdInt = 0x61EC1A; | ||
integer fourthInt = -160693;</ | integer fourthInt = -160693;</source> | ||
The following are NOT integers, use {{LSLG|float}} for them: | The following are NOT integers, use {{LSLG|float}} for them: | ||
< | <source lang="lsl2"> | ||
integer decimalValue = 125.2; // ERROR : Type mismatch -- Integer literals can't have a decimal. | integer decimalValue = 125.2; // ERROR : Type mismatch -- Integer literals can't have a decimal. | ||
integer bigValue = 3147483647; // An undocumented way to say -1,147,483,649 // Integer literals can't be larger than 2,147,483,647. | integer bigValue = 3147483647; // An undocumented way to say -1,147,483,649 // Integer literals can't be larger than 2,147,483,647. | ||
integer biggerValue = 10123456789; // An undocumented way to say -1 // Integer literals can't be larger than 2,147,483,647. | integer biggerValue = 10123456789; // An undocumented way to say -1 // Integer literals can't be larger than 2,147,483,647. | ||
</ | </source> | ||
The following function can be used to determine whether a string of characters consists only of integers. This can be important if you need to know that a user has entered a valid integer in chat or a textbox, for example. | The following function can be used to determine whether a string of characters consists only of integers. This can be important if you need to know that a user has entered a valid integer in chat or a textbox, for example. | ||
< | <source lang="lsl2"> | ||
integer IsInteger(string var) | integer IsInteger(string var) | ||
{ | { | ||
Line 34: | Line 34: | ||
} | } | ||
return TRUE; | return TRUE; | ||
}</ | }</source> | ||
Here's a simpler solution for strings containing positive or negative decimal integers (values from −2147483648 and 2147483647 written without + sign, leading zeros, or thousands separators ',' ). Omei Qunhua. | Here's a simpler solution for strings containing positive or negative decimal integers (values from −2147483648 and 2147483647 written without + sign, leading zeros, or thousands separators ',' ). Omei Qunhua. | ||
< | <source lang="lsl2"> | ||
if ( (string) ( (integer) data) == data) | if ( (string) ( (integer) data) == data) | ||
llOwnerSay("'" + data + "' contains a valid integer"); | llOwnerSay("'" + data + "' contains a valid integer"); | ||
</ | </source> | ||
The following examples will validate that a string contains only the characters 0 though 9. Omei Qunhua. | The following examples will validate that a string contains only the characters 0 though 9. Omei Qunhua. | ||
a) Example for a string of length 5 | a) Example for a string of length 5 | ||
< | <source lang="lsl2"> | ||
StringOf5Dec(string test) | StringOf5Dec(string test) | ||
{ | { | ||
return ( (integer) ("1" + test) >= 100000); | return ( (integer) ("1" + test) >= 100000); | ||
} | } | ||
</ | </source> | ||
b) Example for a string of length 1 through 9 | b) Example for a string of length 1 through 9 | ||
< | <source lang="lsl2"> | ||
VarStringIsDecimal(string test) | VarStringIsDecimal(string test) | ||
{ | { | ||
Line 60: | Line 60: | ||
return ( (integer) ("1" + test) >= limit); | return ( (integer) ("1" + test) >= limit); | ||
} | } | ||
</ | </source> | ||
==Further Reading== | ==Further Reading== | ||
For a more extensive coverage of integers, including the different ways they are used in LSL, see [[LSL_101/LSL_in_Focus:_Integers|LSL in Focus: Integers]]. | For a more extensive coverage of integers, including the different ways they are used in LSL, see [[LSL_101/LSL_in_Focus:_Integers|LSL in Focus: Integers]]. |
Revision as of 02:50, 22 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Integers
The integer data type is a signed 32 bit value between −2,147,483,648 and +2,147,483,647 (that is 0x80000000 to 0x7FFFFFFF in hex). Integers are whole numbers. The fractional datatype is the float.
DEBUG_CHANNEL can be used as a constant for the maximum integer (for that is the value it is defined as).
Examples
All of the following are integers:
integer firstInt = 5512623;
integer secondInt = ACTIVE;
integer thirdInt = 0x61EC1A;
integer fourthInt = -160693;
The following are NOT integers, use float for them:
integer decimalValue = 125.2; // ERROR : Type mismatch -- Integer literals can't have a decimal.
integer bigValue = 3147483647; // An undocumented way to say -1,147,483,649 // Integer literals can't be larger than 2,147,483,647.
integer biggerValue = 10123456789; // An undocumented way to say -1 // Integer literals can't be larger than 2,147,483,647.
The following function can be used to determine whether a string of characters consists only of integers. This can be important if you need to know that a user has entered a valid integer in chat or a textbox, for example.
integer IsInteger(string var)
{
integer i;
for (i=0;i<llStringLength(var);++i)
{
if(!~llListFindList(["1","2","3","4","5","6","7","8","9","0"],[llGetSubString(var,i,i)]))
{
return FALSE;
}
}
return TRUE;
}
Here's a simpler solution for strings containing positive or negative decimal integers (values from −2147483648 and 2147483647 written without + sign, leading zeros, or thousands separators ',' ). Omei Qunhua.
if ( (string) ( (integer) data) == data)
llOwnerSay("'" + data + "' contains a valid integer");
The following examples will validate that a string contains only the characters 0 though 9. Omei Qunhua.
a) Example for a string of length 5
StringOf5Dec(string test)
{
return ( (integer) ("1" + test) >= 100000);
}
b) Example for a string of length 1 through 9
VarStringIsDecimal(string test)
{
integer limit = (integer) llPow(10.0, llStringLength(test) );
return ( (integer) ("1" + test) >= limit);
}
Further Reading
For a more extensive coverage of integers, including the different ways they are used in LSL, see LSL in Focus: Integers.
Subcategories
This category has the following 19 subcategories, out of 19 total.
I
Pages in category "LSL Integer"
The following 46 pages are in this category, out of 649 total.
(previous page) (next page)V
- VEHICLE FLAG NO FLY UP
- VEHICLE ANGULAR DEFLECTION EFFICIENCY
- VEHICLE ANGULAR DEFLECTION TIMESCALE
- VEHICLE ANGULAR FRICTION TIMESCALE
- VEHICLE ANGULAR MOTOR DECAY TIMESCALE
- VEHICLE ANGULAR MOTOR DIRECTION
- VEHICLE ANGULAR MOTOR TIMESCALE
- VEHICLE BANKING EFFICIENCY
- VEHICLE BANKING MIX
- VEHICLE BANKING TIMESCALE
- VEHICLE BUOYANCY
- VEHICLE FLAG CAMERA DECOUPLED
- VEHICLE FLAG HOVER GLOBAL HEIGHT
- VEHICLE FLAG HOVER TERRAIN ONLY
- VEHICLE FLAG HOVER UP ONLY
- VEHICLE FLAG HOVER WATER ONLY
- VEHICLE FLAG LIMIT MOTOR UP
- VEHICLE FLAG LIMIT ROLL ONLY
- VEHICLE FLAG MOUSELOOK BANK
- VEHICLE FLAG MOUSELOOK STEER
- VEHICLE FLAG NO DEFLECTION UP
- VEHICLE HOVER EFFICIENCY
- VEHICLE HOVER HEIGHT
- VEHICLE HOVER TIMESCALE
- VEHICLE LINEAR DEFLECTION EFFICIENCY
- VEHICLE LINEAR DEFLECTION TIMESCALE
- VEHICLE LINEAR FRICTION TIMESCALE
- VEHICLE LINEAR MOTOR DECAY TIMESCALE
- VEHICLE LINEAR MOTOR DIRECTION
- VEHICLE LINEAR MOTOR OFFSET
- VEHICLE LINEAR MOTOR TIMESCALE
- VEHICLE REFERENCE FRAME
- VEHICLE TYPE AIRPLANE
- VEHICLE TYPE BALLOON
- VEHICLE TYPE BOAT
- VEHICLE TYPE CAR
- VEHICLE TYPE NONE
- VEHICLE TYPE SLED
- VEHICLE VERTICAL ATTRACTION EFFICIENCY
- VEHICLE VERTICAL ATTRACTION TIMESCALE
- VERTICAL