LSL Variables

From Second Life Wiki
Revision as of 11:43, 1 February 2007 by Radslns Hutchence (talk | contribs) (need to check formatting. I will update as appropriate.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A variable is a programming term which refers to a place to store information.

LSL is a strongly typed language. This means that variables must be declared by type and that variables may only hold values of a corresponding type.

Variable Conventions

Common Variable Uses

i is an integer used in the outer most loop as an incrementor.

j is an integer used in an inter loop as an incrementor.

Magic Numbers

The phrase "magic number" refers to a number in code, who's meaning is not intuitive from the context of the code and \ or a number repeated throughout the code.

Example:

if ( vctSpd.z < 10 ) { }

In this example 10 is a "magic number". In a scenario where this test is repeated 20 times in the script, a change would require 20 updates and increase the chance of error.

To avoide magic numbers, declare a variable of the appropriate type, set the value of the variable in the declaration and use the variable in your code.

integer intSlowSpeed = 10;

if ( vctSpd.z < intSlowSpeed) { }

updating the value of intSlowSpeed here requires 1 change and reduces the opportunity for error.