Difference between revisions of "LSL Style Guide"
Line 13: | Line 13: | ||
Method One: | Method One: | ||
<pre> | |||
default { | default { | ||
state_entry() { | state_entry() { | ||
Line 19: | Line 19: | ||
} | } | ||
} | } | ||
</pre> | |||
Method Two: | Method Two: | ||
<pre> | |||
default | default | ||
{ | { | ||
Line 30: | Line 30: | ||
} | } | ||
} | } | ||
</pre> | |||
Method One conserves space, however Method Two is easier to read for the beginner. Once a scripter is the practice of using a particular style, reading code in that style will be easier. Consistent indenting makes reading both styles easier. In Method One indenting is the key indicating factor of levels of scope. | |||
Method One conserves space, however Method Two is easier to read for the beginner. | |||
==Naming Conventions== | ==Naming Conventions== | ||
Line 43: | Line 41: | ||
Global Variables (variables used through out the entire program) should begin with a lowercase g. For Example: | Global Variables (variables used through out the entire program) should begin with a lowercase g. For Example: | ||
<pre> | |||
integer gSelected = 0; | integer gSelected = 0; | ||
string gMyName = "Please set one"; | string gMyName = "Please set one"; | ||
</pre> | |||
Variable Constants should be in ALL CAPS. For Example: | Variable Constants should be in ALL CAPS. For Example: | ||
<pre> | |||
integer CHAT_CHAN = -517265; | integer CHAT_CHAN = -517265; | ||
key OWNER_KEY = llGetOwner(); | key OWNER_KEY = llGetOwner(); | ||
</pre> | |||
==Script Structure== | ==Script Structure== | ||
LSL scripts are comprised of expressions, functions, statements, event handlers and states. | LSL scripts are comprised of expressions, functions, statements, event handlers and states. The LSL compiler mandates a certain structure to scripts: | ||
#User defined variables and functions | |||
#[[default]] state | |||
#User Defined States | |||
===Indentation=== | ===Indentation=== | ||
Line 91: | Line 70: | ||
===Syntax Highlighting=== | ===Syntax Highlighting=== | ||
There are many 3rd party editors with LSL syntax files. | |||
See [[LSL Alternate Editors]] for more information. |
Revision as of 11:25, 8 May 2007
Effective programming in LSL requires that developers use a disciplined practice for applying formatting and convention to their scripts.
These guidelines, referred to collectively as a Style Guide, are not as rigid as the rules required by the language compiler but nonetheless are critical to creating maintainable code. The most critical aspect of a style is that you apply it consistently to the code you write.
General Guidelines
Most people, when they start programming on their own, will have programs that are UGLY to look at; to put it nicely. They usually look like the following:
default {state_entry(){llSay(0,"Hello World.");}}
However, that code is impossible to read (or at least to follow) when one is writing a ten thousand word program. Therefore, programmers have two main methods as to bracketing.
Method One:
default { state_entry() { llSay(0, "Hello World."); } }
Method Two:
default { state_entry() { llSay(0, "Hello World."); } }
Method One conserves space, however Method Two is easier to read for the beginner. Once a scripter is the practice of using a particular style, reading code in that style will be easier. Consistent indenting makes reading both styles easier. In Method One indenting is the key indicating factor of levels of scope.
Naming Conventions
There are many naming conventions in Second Life. Only the most used ones will be listed below.
Global Variables (variables used through out the entire program) should begin with a lowercase g. For Example:
integer gSelected = 0; string gMyName = "Please set one";
Variable Constants should be in ALL CAPS. For Example:
integer CHAT_CHAN = -517265; key OWNER_KEY = llGetOwner();
Script Structure
LSL scripts are comprised of expressions, functions, statements, event handlers and states. The LSL compiler mandates a certain structure to scripts:
- User defined variables and functions
- default state
- User Defined States
Indentation
Editor
One of the best text editors i have found is text pad ( textpad_site )
Syntax Highlighting
There are many 3rd party editors with LSL syntax files. See LSL Alternate Editors for more information.