EditOverview
Arena Scripts are to a Gear what a brain is to a person. While a solid weapon system is essential, the Gear still requires a strategy to use those weapons. The arena script syntax is loosely based on Javascript, and was designed to be easy to read and modify. You are allowed to have as many scripts as you like, but you must choose one as the default combat script that will be used by your Gear in the arena. Arena Scripts are case insensitive, so the variable $abc is the same as $ABC.
EditComments
Comments are allowed in the arena script. Comments are single line, and begin with two forward slashes '//'.
// my comment
EditVariables
There are two types of variables: user defined and system controlled. User defined variables are declared at the beginning of the script and have global scope.
System Controlled Variables are controlled by the gear (read-only in the script) and updated as the combat match progresses. All user defined variables begin with a dollar sign '$', and each system controlled variable starts with an at sign '@'. Both variable types can only contain numbers, letters, and underscores. Variables hold the following data types: float (real numbers), string ("hello"), and boolean (true or false).
vars $myVar, $my2Var, $and_SoOn
sub mySub
{
$myVar = 1
$myVar = 1.23
$myVar = "Hello World"
$myVar = true
$my2Var = $myVar
@MortarRange = 123 // error
}
EditOperators
An operator combines one or more values and yields another value. Operators can be used to compare two values, or perform math with two values. Within the arena script, there are 2 logical operators (and, or), 6 relational operators (==, !=, <=, <, >=, >), 1 string operator(&), 4 math operators (+, -, /, *), and 3 unary operators (not, -, %). In terms of precedence, unary operators are evaluated first, followed by math operators, then string, relational and finally logical.
Syntax for Operators and accepted alternatives:
AND and && true and false true && false
OR or || true or false true || false
EQUAL == true == false
NOT EQUAL != <> true != false true <> false
GREATER THAN > 1 > 2
GREATER THAN OR EQUAL >= 2 >= 3
LESS THAN < 1 < 2
LESS THAN OR EQUAL <= 2 <= 3
MULTIPLY * 4 * 5
DIVIDE / 4 / 5
ADD + 4 + 5
SUBTRACT - 4 - 5
STRING CONCAT & "I am number " & 45 & ", that is all"
NOT not ! not true ! true
NEGATE - -4
PERCENT % 53%
Note: The '%' will automatically convert a percentage value to a decimal value. The unary percent operator makes your arena script a bit easier to read. For instance, 50% is the same as 50/100: '(@hp / @maxHp) < 50%' can be read as 'if my HP is less than 50% of max HP'. Those who are used to C style languages, and using the '%' as a modulus operator will have to rely on the 'mod' function to determine if a value has a remainder.
Example of unary percent operator:
if (@ep / @maxEp < 50%)
{
Recharge()
}
EditControl Structures
Arena script is built out of a series of statements. A statement can be an assignment, a function call, or a conditional statement. The single most important statements are going to be the control statements: if and select.
The if statement allows for conditional execution of code fragments. Aena Script features an if structure that is similar to that of C, but with in caveat; the braces are required. If expression evaluates to TRUE, the script will execute the body of code, and if it evaluates to FALSE - it will ignore it.
if (expression)
{
// body of code
}
There are times when you want to execute a statement if a certain condition is met, and a different statement if the condition is not met. An if/else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE. The else statement is only executed if the if expression evaluated to FALSE.
if (expression)
{
// body of code
}
else
{
// else body of code
}
The select statement is a combination of boolean expressions identified by the when keyword. Only one of these when blocks will be executed if it evaluates to TRUE. If none evaluate to TRUE, nothing is executed from within the select statement.
select
{
when ($a == 1)
{
// body of code
}
when ($a == 2)
{
// body of code
}
}
EditSub Routines
A user defined sub routine may be defined using the following syntax:
vars $a, $b
sub mySub($c) vars $d
{
dosub mySecondSub("Hello") //dosub:mySecondSub("Hello") is also valid
}
sub mySecondSub($c) vars $e
{
if ($c == "Hello")
{
// body of code
return
}
}
A sub routine cannot return any values. The parameters and variables are optional when creating a sub routine. Parameters and variables that are defined with a sub routine, are local to that sub routine, and cannot have the same name as a global variable. The return keyword is used to end processing of the current sub routine, and return to the caller. User defined sub routines are called or executed using the keyword dosub.
EditFunctions
A user defined function may be defined using the following syntax:
vars $a, $b
func add($d, $e)
{
return (1 + 2)
}
sub mySub($c) vars $d
{
if (dofunc:add(1, 2) == 3) // if (dofunc add(1,2) == 3) is also valid
{
// body of code
}
else
{
// else body of code
}
}
A function must return a value. The parameters and variables are optional when creating a function. Parameters and variables that are defined with a function, are local to that function, and cannot have the same name as a global variable. The return keyword with an expression enclosed within parenthesis are used to end processing of the current function, and return the expression value to the caller. User defined functions are called or executed using the keyword dofunc followed by a colon and the name of the function.
EditScript Events
Script Events may be defined using the following syntax with the keyword on:
on myTurn vars $a
{
// move gear 1 unit to the right
MoveTo(@PosX + 1, @PosY)
}
Script Events are called by the game engine, and cannot be invoked directly. Events are called when "things" happen during a combat match, such as attacked. Whenever your gear is attacked the 'on attacked' event will be fired or called. You are not required to use, or define, all of the system defined events: only the ones you are interested in to make sure your gear makes it to #1.