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

LSL Wiki : Constants

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

Constants


Constants are pre-defined values that do not change--they're constant: TRUE will always equal 1. However, this does not mean that values should be used instead; while there's no technical reason not to, constants exist to simplify your code and make it easier to understand. It's good coding practice to use them.

This page is for general constants; function-specific ones should be documented on the functions page.
You can find an almost complete list of constants & values on LexFile.


float

PI 3.1415926535897932384626433832795 (pi)
TWO_PI 6.283185307179586476925286766559 (pi * 2)
PI_BY_TWO 1.5707963267948966192313216916398 (pi / 2)
DEG_TO_RAD To convert from degrees to radians (multiply, example: radian = 90 * DEG_TO_RAD;)
RAD_TO_DEG To convert to radians from degrees (multiply, example: degree = PI_BY_TWO * RAD_TO_DEG;)
SQRT2 1.4142135623730950488016887242097 (square root of 2)


integer

TRUE 1, an integer constant for boolean operations.
FALSE 0, an integer constant for boolean operations.
DEBUG_CHANNEL 2147483647, a special chat channel used to print to the Script Error Window.
PUBLIC_CHANNEL 0, chat channel that broadcasts to all nearby users.
OBJECT_UNKNOWN_DETAIL -1, an integer returned when an invalid object parameter type is passed to llGetObjectDetails.
INVENTORY_NONE -1, an integer returned by llGetInventoryType when no item is found.


string

NULL_KEY Indicates an empty key: "00000000-0000-0000-0000-000000000000". This constant is typed as a string not as a key.


EOF, "\n\n\n", Indicates the last line (or a line past this) of a notecard was read (returned in the dataserver event), or that the notecard contained embedded objects.

SubstringReplaced With
\tfour spaces
\nnew line
\"double quote
\\backslash

rotation

ZERO_ROTATION <0.0, 0.0, 0.0, 1.0> (Note that ZERO_ROTATION is not <0.0, 0.0, 0.0, 0.0>! This is important.)


vector

ZERO_VECTOR <0.0, 0.0, 0.0>


object type
AGENT 1
ACTIVE 2
PASSIVE 4
SCRIPTED 8

For more info see object types

Also, see annoyances for a partial reason for explicitly specifying floating-point constants in the vector and rotation definitions. Using integers can cause logical-looking calculations in assignments to fail in ways that can be difficult to notice at first due to the way LSL parses numbers and handles inline math operations using the fastest data type.


Functions | Events | Types
Comments [Hide comments/form]
I just want to make it clear that I hate this page and want to put up both seperate entries for each constant, as well as all the function-specific contants on the page of that function. Added it to ToDo. :)
-- CatherineOmega (2004-01-26 11:20:01)
Good idea.
-- GuzarFonzarelli (2004-01-26 12:46:36)
Okay, I like this page now. :)
-- CatherineOmega (2004-03-24 16:27:31)
Whoops... sorry about that. I made a correction to this page, but didn't make an account here first. In the table with the TRUE and FALSE constants in it, the 0 and 1 were reversed. It was saying that TRUE was 0 and FALSE was 1, which is, of course, incorrect.
-- DeltaCzukor (2005-06-26 22:55:17)
Thats alright, if you see anything else that needs changing go right ahead. Most of the pages require an account to edit them but some haven't been set that way yet.
-- BlindWanderer (2005-06-27 17:35:56)
Let's keep the unnecessary ".0"s to a minimum (preferably not at all, actually), eh?
-- EepQuirk (2005-08-14 23:04:16)
Keep in mind that the ".0" can help enunciate the fact that the constant consists of floating point values.
-- ChristopherOmega (2005-08-15 01:07:48)
Any idiot knows vectors are made of floats...and a quick look at the vector page can verify this...
-- EepQuirk (2005-08-16 18:59:17)
You really do have a habit of thinking that since something is 'obvious' to you, it's obvious to everyone else, Eep.

I vote for keeping the .0's for the same reason as mentioned, and because of some of the unfortunate annoyances (especially the integer division problem) it is likely to save a lot of grief for beginning programmers to see that you should always (at first at least) use decimal points all the time in vector and rotation assignments and constants.
-- WolfWings (2005-08-30 23:09:07)
Is it possible to have another page added like this one that's a list of Function-specific Constants, just so we know what they are at a glance (useful if we want the constants but don't want to look through every function to find them).
-- GrazelCosmo (2005-10-22 02:44:51)
that would be good, constants and what functions they can be used for
-- Turnni1 (2007-01-13 06:26:48)
Take a look at the table on LexFile
-- BlindWanderer (2007-01-14 12:48:25)
If ".0" is good coding practice, it's also good documentation practice. It should always be used with a float, in both cases. I also recall seeing something, I don't know if it was correct, that the LSL compiler generates extra bytecode if it has to do implicit type coversion (e.g. vecColor = <1, 1, 1>)

I also think it would be good to have a centralized reference for all LSL constants. The LexFile is fine, but not really easy to use. Unless someone has a better idea, I'm going to start importing function-specific constants to this page.
-- adsl-75-41-6-159.dsl.klmzmi.sbcglobal.net (2007-08-11 11:30:45)
I've added the constant PUBLIC_CHANNEL. If anyone has a problem with it, feel free to remove it.
-- blk-222-70-198.eastlink.ca (2007-12-30 07:53:58)
I'm the person who commented above. I also added OBJECT_UNKNOWN_DETAIL and INVENTORY_NONE to the list of integer constants, since they seem like somewhat useful info if you like making your code look more descriptive. :P
-- NidolSlazar (2007-12-30 13:49:53)
Attach a comment to this page: