VARIABLES
Variables provide a place to store temporary working values. Variables can be both global and local. Global
variables are available to everything in the script, while local variables are available only to the block they
were defined in. A variable name must start with an ASCII letter or an underscore. Numerals may be part
of a variable name after the first character, and non-ASCII letters, while allowed, are ignored. Thus, valid
declarations include the following:
integer x;
integer y1;
integer _z;
integer thisIs_ALongComplicatedVariable_42;
integer enumerator;
integer _enumerator;
integer énumérateur; // same as numrateur
However, you can not also declare an integer numrateur because LSL ignores the é, and
thus thinks the name has previously been declared in scope; that is, numrateur is the same variable as
énumérateur.
(MPCBMWBSJBCMFTBOEDPOTUBOUTNVTUCFEFGJOFECFGPSFUIFdefault state, as shown in the
following code:
integer gFoo = 42;
default
{
on_rez(integer start_param) {
llOwnerSay("gFoo is "+(string)gFoo);
}
}
Variables can not CFEFGJOFEEJSFDUMZJOTJEFTUBUFTUIFZNVTUBQQFBSJOTJEFCMPDLTGVODUJPOTPSFWFOU
handlers). Thus, a slight rearrangement of the preceding code will generate a syntax error:
default
{
integer gFoo = 42;
on_rez(integer start_param) {
llOwnerSay("gFoo is "+(string)gFoo);
}
}
Local variables must always be declared within the scopeFODMPTJOHDVSMZCSBDFTPGBGVODUJPOPSFWFOU
handler but needn't be declared before the first executable statement. Just declare it prior to its first use
and you'll be fine. Consider the following example:
foo() {
integer bar = 0;
llOwnerSay("bar is "+(string)bar);
integer baz = 0;
llOwnerSay("baz is "+(string)baz);
}

Get Scripting Your World: The Official Guide to Second Life® Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.