Typecast
Revision as of 11:32, 3 September 2007 by Strife Onizuka (talk | contribs) (New page: {{LSL Header}}{{LSLC|Syntax}}{{RightToc}} To convert the type of a value a typecast is required. There are two types of typecasting, explicit and implicit. Explicit typecasts must be prov...)
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
To convert the type of a value a typecast is required. There are two types of typecasting, explicit and implicit. Explicit typecasts must be provided by the programmer, but implicit typecasts are put in place by the compiler. LSL implicitly typecasts strings to keys and integers to floats where the latter type is required but the former is provided.
Syntax: (type)value
Converts value to type.
• expression | type | – | variable type | |
• expression | value | – | expression or constant |
Examples
string a = "1.5"; float b = (float)a; integer c = (integer)a;
Caveats
- The compiler allows explicit typecasting where it is not needed and does not optimize it out. Unnecessary typecasts will bloat code and slow it down.