Don't click here unless you want to be banned.

LSL Wiki : Types

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are


Variables, function parameters, and return values have types. This means that a value stored in a variable, bound to a function parameter, or returned by a function must be of the same type, or it must be converted to the same type.

LSL provides a set of seven basic types that are used throughout the language:

Type Brief Description
integer A whole number ranging from -2,147,483,648 to 2,147,483,647
float A decimal number ranging from 1.175494351E-38 to 3.402823466E+38
vector Three floats in the form < x , y , z >. Usually a position, color, or Euler rotation
rotation A quaternion rotation, made up of 4 floats, < x , y , z , s >
key A UUID (specialized string) used to identify something in SL, notably an agent, object, sound, texture, other inventory item, or dataserver request
string A sequence of characters, limited only by the amount of free memory available to the script.
list A heterogeneous list of the other data types.

To convert between different types of values, use typecasting. An explicit typecast looks like this: ((newType)expression). Implicit typecasting will convert integers to floats or strings to keys.

For example, to say an integer, it must be converted to a string:
integer x = 5;
llSay(0, (string)x);

Constant Value Function
TYPE_INTEGER 1 Indicates that the list entry is holding an integer.
TYPE_FLOAT 2 Indicates that the list entry is holding a float.
TYPE_STRING 3 Indicates that the list entry is holding a string.
TYPE_KEY 4 Indicates that the list entry is holding a key.
TYPE_VECTOR 5 Indicates that the list entry is holding a vector.
TYPE_ROTATION 6 Indicates that the list entry is holding a rotation.
TYPE_INVALID 0 Indicates that this wasn't a valid list entry.
Occurs when passing an index greater than the length of the list or less than the negative length of the list.

This function can be used to loosely determine the type of a variable. Make sure to improve it if you plan to use it for userdata.
// Writen by Chad Statosky
integer GetType(string var)
    integer n =     llGetListLength(llParseStringKeepNulls(var, ["1", "2", "3", "4"], [])) - 1;
            n +=    llGetListLength(llParseStringKeepNulls(var, ["5", "6", "7", "8"], [])) - 1;
            n +=    llGetListLength(llParseStringKeepNulls(var, ["9", "0", ".", "<"], [])) - 1;
            n +=    llGetListLength(llParseStringKeepNulls(var, [">", " ", ",", "-"], [])) - 1;
    if(n == llStringLength(var))
        if(llSubStringIndex(var, "<")  != -1 || llSubStringIndex(var, ">") != -1)
            if(llGetListLength(llParseStringKeepNulls(var, [","], [])) == 3)    return TYPE_VECTOR;
            else                                                                return TYPE_ROTATION;
            if(llSubStringIndex(var, ".") != -1)                                return TYPE_FLOAT;
            else                                                                return TYPE_INTEGER;
        if(llStringLength(var) == 36 && 
                llGetListLength(llParseStringKeepNulls(var, ["-"], [])) == 5)   return TYPE_KEY;
        else                                                                    return TYPE_STRING;

Functions | Constants | Memory Usages
Comments [Hide comments/form]
Why not have separate pages for these?
-- GuzarFonzarelli (2004-01-30 13:53:36)
Yes, these should each have their own seperate entry as well as this page, explaining and contrasting each individual type.
-- CatherineOmega (2004-02-02 20:47:56)
Does constraining a float (using f or F) reduce the memory usage of that float?
-- ChristopherOmega (2004-02-17 20:33:15)
I don't think there's a separate variable in LSL for doubles, so I doubt it.
-- GuzarFonzarelli (2004-02-17 22:21:14)
Where are implicit and explicit typecasts covered?
-- ChristopherOmega (2004-04-26 21:49:22)
I killed off all of the individual entries on this page, updating their respective individual entries. Now we should have an easier time of keeping them up to date...
-- KeknehvPsaltery (2005-06-21 16:03:10)
I believe this page is one that I used to consider extremely useful, with well written, detailed information in well laid out form that was very good for people to get an introduction to types. It is sad if the page I liked for years is gone.
-- SuezanneCBaskerville (2006-07-22 00:19:18)
I agree with Suezanne. Definitions of these foundation types should be very well explained, in detail. It's not so much anymore.. just a breif definition and a useless script. (What I mean by useless is... Sure, it's a script that does what people are looking for. But... I almost wanna look at it and edit it to 'No kidding'. if the definition was detailed, that script would be pointless. It just is there because someone feels proud.)
-- BirdRaven (2006-07-22 10:49:04)
I beleive the information was removed so it could be found on the individual data type pages.

And that function, is so flawed it's not even worth fixing.
-- BlindWanderer (2006-07-22 12:12:24)
Edited GetType code to include support for negative values in number types, and removed the return value for TYPE_INVALID for three reasons: 1. Compiler complained that the return value would never be called due to the way the logic was setup, 2. The example code wouldn't compile with that code there (All examples should at least compile), and 3. This user function can't determine whether a string is TYPE_INVALID in the first place.
-- HankRamos (2006-08-27 11:22:37)
Attach a comment to this page: