Last modified 4 years ago Last modified on 08/24/08 11:58:44

String expressions

Strings are put inside quotation marks: "some text inside quotation marks is a legal string".

Strings can be easily concatenated using the & operator.

For example: "String1" & "String2" will result in "String1String2".

Strings can be compared using == operator (case insensitive comparison) or strcmp() function.

Such data types as integers, booleans and floats are automatically converted to strings when it is required, so given the following variable declaration:

private float pi; private int myInteger; private string myString; private bool myBool;

The following line is a valid string expression:

console("value of pi is " & pi & ", value of myInteger is " & myInteger & ", value of myString is " & myString & ", value of myBool is " & myBool);

Numeric expressions

Numeric expressions are made up of int variables, numeric constants and functions that return int values, e. g.:

power * 32 - basePower numDroids(player) + 5

The possible operators are: + - * /

Increment and decrement operators can only be applied to the integer variables outside of the expression context:

myInteger++; myInteger--;

There are also a number of operators that compare numeric expressions to give a boolean.

{

!Operator !Meaning

|< |Less than

|> |Greater than

|<= |Less than or equal

|>= |Greater than or equal

|== |Equal

|!= |Not equal |}

Boolean expressions

Boolean expressions are made up of bool variables, the boolean constants TRUE and FALSE and game functions that return a boolean value e.g.:

not droidSeen and attackDroid

The possible operators are:

{

!Operator !Meaning

|bool1 and bool2 |True if bool1 and bool2 are true

|bool1 or bool2 |True if at least one of bool1 and bool2 is true

|not bool1 |True becomes false and false becomes true

|== |Can also be used with user defined type variables

|!= |Can also be used with user defined type variables |}

Floating point expressions

Floating point expressions are very similar to integer expressions. There are some differences though: it is not possible to use increment/decrement operators with floating point variables. The integral and fractional parts of the float constant must be separated by a dot, even if fractional part is 0.

Example:

myFloat = 1.0 + pi / 2.0 + 3.6;

Floating point expressions cannot be mixed with integer or boolean expressions. To use integers or booleans in floating point expressions they must be cast to FLOATs first.

See casts ? for more information on casting.

{{Scripting manual}} Category:Scripting manual ?