Difference between revisions of "LSL 101/Simple Script Skeleton"
Line 1: | Line 1: | ||
Here is the simplest possible valid LSL script. It doesn't actually ask the computer to do anything but all scripts have, at minimum, this structure: | |||
<lsl> | <lsl> | ||
Line 12: | Line 12: | ||
Looking at this, the first thing you might notice is that the ratio of punctuation to words is quite high. This is a general characteristic of LSL. Along with parenthesis and curly braces, there will be lots of semicolons, quotation marks and square brackets, and it all has to be done just right. Fortunately, the rules for using punctuation are much simpler than for a natural language. So even though you are likely to struggle a lot with punctuation at the beginning, that phase won't last long. | Looking at this, the first thing you might notice is that the ratio of punctuation to words is quite high. This is a general characteristic of LSL. Along with parenthesis and curly braces, there will be lots of semicolons, quotation marks and square brackets, and it all has to be done just right. Fortunately, the rules for using punctuation are much simpler than for a natural language. So even though you are likely to struggle a lot with punctuation at the beginning, that phase won't last long. | ||
In addition to the punctuation, there are two | In addition to the punctuation, there are two "names" in this example, "default" and "state_entry". In LSL, the underscore is not a punctuation mark, but one of the characters that can be used in names. It's most often used to combine what might be multiple words in English into a single name, because LSL requires every name to be a single word. | ||
Based on the example, you might guess that there is a recurring pattern of the form | |||
<lsl> | |||
heading | |||
{ | |||
... | |||
} | |||
</lsl> | |||
in LSL, and you would be absolutely right. Each one of these is called a <b>block</b>, and a large part of an LSL script is made up of blocks within blocks (within blocks ...). Since getting the punctuation just right is mandatory, it is a good idea to vertically align opening and closing curly braces with their heading, and indent everything in between. | |||
(For an alternative possible order of (or maybe philosophy of?) development, see [[LSL 101/Simple Script Skeleton(A)]].) | (For an alternative possible order of (or maybe philosophy of?) development, see [[LSL 101/Simple Script Skeleton(A)]].) |
Revision as of 16:08, 6 May 2009
Here is the simplest possible valid LSL script. It doesn't actually ask the computer to do anything but all scripts have, at minimum, this structure:
<lsl> default {
state_entry() { }
} </lsl>
Looking at this, the first thing you might notice is that the ratio of punctuation to words is quite high. This is a general characteristic of LSL. Along with parenthesis and curly braces, there will be lots of semicolons, quotation marks and square brackets, and it all has to be done just right. Fortunately, the rules for using punctuation are much simpler than for a natural language. So even though you are likely to struggle a lot with punctuation at the beginning, that phase won't last long.
In addition to the punctuation, there are two "names" in this example, "default" and "state_entry". In LSL, the underscore is not a punctuation mark, but one of the characters that can be used in names. It's most often used to combine what might be multiple words in English into a single name, because LSL requires every name to be a single word.
Based on the example, you might guess that there is a recurring pattern of the form <lsl> heading {
...
} </lsl> in LSL, and you would be absolutely right. Each one of these is called a block, and a large part of an LSL script is made up of blocks within blocks (within blocks ...). Since getting the punctuation just right is mandatory, it is a good idea to vertically align opening and closing curly braces with their heading, and indent everything in between.
(For an alternative possible order of (or maybe philosophy of?) development, see LSL 101/Simple Script Skeleton(A).)