Chapter Listing
< 1 2 3 4 5 6 7 8 9 >
2) Values
Values (
variables, "
constants", literals, etc):
variable -- has a name, has a value, value can change.
constant -- has a name, has a value which is fixed -- LSL has no real constant support, but when they're necessary, you can fake a constant by using a variable, and never changing its value.
literal -- an actual value that can be assigned to a variable, or used as an
argument. (you'll get to this in a sec)
Values have what's called a
type as well.
Integer,
float and
string are the most common ones. For a complete list, as well as a discussion of the differences, see the
types page.
Examples of usage:
Declaring a variable:
integer score = 0;
string loginName;
The initial (or default) value of 0 has been assigned to a variable
score of the type
integer. The default value of the variable is optional. Some languages offer implicit default values (usually 0 for integers, the empty string for strings, etc). It's generally intuitive, if supported. The variable
loginName of type
string is declared, and is empty by implicit default.
Declaring a constant:
It's a good idea to identify constants in a different style than variables, so give a visual reminder that they are not to be modified. I use ALL-CAPS, usually. Note: a default value is specified, and it should be expected by the programmer that this value will not change at runtime.
Technically, LSL does NOT have constants; rather this is a (good) formatting suggestion of a variable.
- I (author) agree; thanks for pointing that out. :-)
Using a literal:
Here,
loginName from our earlier example is being re-assigned to contain the literal string "testuser". So, "testuser" is a literal.
You should take a brief look at the complete list of
types. It explains the difference between each one.
Previous |
Next
Homepage |
Tutorial |
CrashCourse |
Glossary