LSL 101/Comments, White-space and Formatting

From Second Life Wiki
Jump to navigation Jump to search

Here's another valid LSL script. <lsl> // This is a valid, but horribly formatted, script default{state_entry(){}} </lsl> The first line is called a comment. Anything on a single line that follows a // is ignored by the computer. Comments are intended solely for the human reader of the script. Since a successful script will invariable be read by humans, it's just as important to make them understandable to humans as to the computer that is going to execute them. In general, the most useful comments are those that explain the script on a higher level than the individual LSL statements. An explanation of what a section of script is intended to do is much more helpful that a line-by-line translation of LSL commands into English.

The second thing this script illustrates is that white space (blanks, tabs and separate lines) are, for the most part, entirely optional. The major exceptions are that a new line always ends a comment and you can't insert a space or tab in a number. For example, you can't write <lsl>

    // These are NOT valid LSL fragments
    state entry     // This would be interpreted as two separate names
    123 456         // ... and this as two separate numbers.

</lsl>