scripting:basic_syntax
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| scripting:basic_syntax [2012/03/25 18:34] – created mit | scripting:basic_syntax [2025/05/28 16:34] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 31: | Line 31: | ||
| * ''< | * ''< | ||
| * ''> | * ''> | ||
| + | |||
| + | ===== Loops ===== | ||
| + | '' | ||
| + | < | ||
| + | $loop = 0 | ||
| + | while ( $loop < 10 ) | ||
| + | { | ||
| + | | ||
| + | $loop += 1 | ||
| + | } | ||
| + | </ | ||
| ===== Comments ===== | ===== Comments ===== | ||
| Line 48: | Line 59: | ||
| < | < | ||
| - | $var = $var + 1 | + | $var = 1 |
| | | ||
| + | $var += 1 | ||
| </ | </ | ||
| - | Currently | + | Currently the 4 basic operators ( '' |
| + | |||
| + | ===== Local, Module & Global Variables ===== | ||
| + | |||
| + | Local variables can be used at any point without advance declaration. They remain in scope throughout the event or function as you'd expect. | ||
| + | Module variables (those that are instantiated outside of an event or function) remain in scope for all events and functions within the file until the script is reloaded or the server is restarted. | ||
| + | Global variables are declared using the keyword ' | ||
| + | |||
| + | Example Local variable use : | ||
| + | < | ||
| + | Event( " | ||
| + | { | ||
| + | | ||
| + | if ( $myage = 6 ) | ||
| + | { | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | Example module variable use : | ||
| + | < | ||
| + | $mNumberOfBongoPlays = 0 | ||
| + | Event( " | ||
| + | { | ||
| + | | ||
| + | *say $mNumberOfBongoPlays people have played the bongos since the script was last restarted | ||
| + | } | ||
| + | </ | ||
| + | Example global variable use : | ||
| + | < | ||
| + | global $kNumberOfBongoPlays = 0 | ||
| + | Event( " | ||
| + | { | ||
| + | | ||
| + | *say $kNumberOfBongoPlays people have played the bongos since the script was last restarted | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Arrays ===== | ||
| + | |||
| + | Local, module and global arrays can be created. Arrays can contain values and text. Array indexing starts from 1, which is a bit annoying if you've got any sense at all but hey ho. | ||
| + | |||
| + | Arrays | ||
| + | |||
| + | < | ||
| + | $maTestArray[] = | ||
| + | { | ||
| + | 100, " | ||
| + | 200, " | ||
| + | } | ||
| + | |||
| + | Event( "& | ||
| + | { | ||
| + | *say The first value in the array is $maTestArray[1] | ||
| + | *say The second text item in the array is $maTestArray[4] | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | .. which would print 'The first value in the array is 100' followed by 'The second text item in the array is Item 2'. | ||
| + | |||
| + | |||
| + | >> * [[Scripting: | ||
scripting/basic_syntax.1332700491.txt.gz · Last modified: (external edit)
