The scripting language supports a limited range of the basic syntactical components that make up most similar-level programming languages
if
, else
and else if
are supported, for example…
if ( $itemNum = 112 ) { *grantskill %PLAYER% Blacksmith } else if ( $itemNum = 113 ) { *grantskill %PLAYER% Scientist } else { *msg %PLAYER% You didnt learn anything new today }
Supported conditions inside an if
or else if
are:
=
(or ==
) <
>
!=
(or <>
) ⇐
( < =
) >=
while
loops are supported, for example…
$loop = 0 while ( $loop < 10 ) { DoMyFunction( $loop ) $loop += 1 }
Code comments are simple C-stylee, e.g
// Check the item number if ( $itemNum = 112 ) { // *say Nothing (this line is commented out) }
Basic maths operators are supported in simple form. Compound operations are not yet supported so each line needs to be kept to a single operation, e.g. :
$var = 1 $newvar = $var * 100 $var += 1
Currently the 4 basic operators ( +, -, /, *
) are supported, along with ( +=, -=, /=, *=
) for operating on the LHS variable (e.g. $var += 1
is equivalent to $var = $var + 1
.
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 'global' and are available to all functions and events in any file.
Example Local variable use :
Event( "UseItem", "Bongos" ) { $myage = $gPlayerAge / 10 if ( $myage = 6 ) { *say I'm in my sixties and im still playing the bongos } }
Example module variable use :
$mNumberOfBongoPlays = 0 Event( "UseItem", "Bongos" ) { $mNumberOfBongoPlays = $mNumberOfBongoPlays + 1 *say $mNumberOfBongoPlays people have played the bongos since the script was last restarted }
Example global variable use :
global $kNumberOfBongoPlays = 0 Event( "UseItem", "Bongos" ) { $kNumberOfBongoPlays = $kNumberOfBongoPlays + 1 *say $kNumberOfBongoPlays people have played the bongos since the script was last restarted }
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 are declared and referenced as shown :
$maTestArray[] = { 100, "Item 1", 200, "Item 2", } Event( "&command", "TestArray" ) { *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'.