EQWatcher Evolution > Scripting  > Statements


Statements describe algorithmic actions that can be executed.  There are several types of statements:

Assignment statement

Assignment statements replace the current value of a variable with a new value specified by an expression. The expression must be compatible with the type of the variable.  These statements generally appear like this:

variable=expression;

Where expression is a mathematical expression manipulating the variable, which may include function calls that return values.  The variable for this type of assignment can be any type (except for string), as long as the expression results in the same data type.  For example, variable=2*3+variable+anothervariable*7;

Order of operation is: : ^ && || * / % + - in that order.  : is used for powers (previous versions used ^).  ^ is now assigned to XOR.  && is logical AND.  || is logical OR.  % is the modulus operator as expected (x=y%z is basically how you divide y by z and set x equal to the remainder).  The order of XOR, AND, and OR may be different than other languages, take care to use parentheses where necessary to make the code more readable and prevent incorrect calculations.  There is also the unary NOT operator, which is !.  This is called unary because it is independent of any value on the left of what you are calculating.  This is basically a quick way to do test if a value is equal to zero (!0 is 1, !x where x is not zero, will always be 0).

There is also the ability to concatenate strings using the + operator.  Limitations are: the end result must be a string, and the left side of the first + must be a string.

Also available as shortcuts for "x=x+1" and "x=x-1" are:

variable++;

variable--;

Though this in C/C++ makes the variable increment (or decrement for --) itself AFTER the current statement is complete, this language requires they be used on their own line, and may not be used in an expression.  They return no value to be used, to avoid C/C++ programmers using it as if it would not be incremented right away.  This acts more like ++variable :)

If statement

The if statement generally appears like this:

if ([Condition])
{
 
[Commands]
}

Condition understands the following operators: == (equal to, that's double equal signs), >= (greater than or equal to), >, <= (less than or equal to, <, != (not equal to).  Each side of the operator is considered an expression and will be evaluated as such.  This expression can involve function calls that return values.  These conditions only work for non-string values.  String comparison techniques are explained in another section.  Please note that unlike the C language, ! cannot be used as a NOT flag except in the != condition (so you cannot do if(!expression) ).

The statements are only executed "if" the condition is met.  If the condition is "1>2" then of course the statements will not be run. 

Another form of the if statement is:

if ([Condition])
{
 
[Statements]
}
else
{
 
[Other Statements]
}

This will run much the same way, except that the other statements will only be run if the condition is NOT met.  If statements can be "nested" or placed inside each other, but each and every if and else statement MUST have its own set of brackets.

if ([Condition])
{
  if (
[Condition])
  {
   
[Statements]
  }
}

This causes statements to run only if BOTH conditions are met, since one is nested inside the other and will only be run if the first condition is met.

While statement

There is currently only one type of loop, in which the condition is set at the start of the loop.

while([Condition])
{
 
[Statements]
}

This will cause EQWatcher to loop until the condition is no longer met at the start of the loop.  The condition is NOT continually checked while looping, ONLY at the beginning.  In old style BASIC terms:

10 if condition goto 40
20 rem statements
30 goto 10
40 rem end loop

That should help you understand if you are having troubles.

Please be very careful of infinite loops or extremely long loops, they may cause ugly side effects.

Continue statement

The continue statement is used to skip the rest of a while loop immediately, returning to the top of the loop.  Generally this is used when a continuing a loop is a useless waste of time or if it will cause an error.

A suggested use is as follows:

while([Condition])
{
 
[Statements]
  if (
[Condition])
  {
    continue;
  }
 
[Statements]
}

Break statement

The break statement is used to exit a while loop immediately.  Generally this is used when a continuing a loop is a useless waste of time or if it will cause an error.

A suggested use is as follows:

while([Condition])
{
 
[Statements]
  if (
[Condition])
  {
    break;
  }
 
[Statements]
}

Return statement

The return statement is to exit a function immediately with a numeric value.  By default, all functions return the value 0 at the end.  A return 0 instruction at the end of a function is therefore redundant and not needed (and takes up more precious processing time).

Syntax is as follows:

return [expression];

The expression may not evaluate to a string value (i.e. must be numeric).

#include Directive

The include compiler directive allows you to write reusable code in a separate file, and import them... or make your large scripts look prettier by breaking them into parts (such as the core script).  Only one main() function is allowed, so you may not #include complete scripts.

The syntax is:

#include "[filename]"

The filename may include an absolute path and filename.  If it is a relative path, the directory used as your script directory will be checked first, and then the default source directory used by me (thus #include "dynarray.eas" will first look in your script's source directory, and then in EQWatcher Evolution\source).

The imported code is added to the END of the script, not at the current point.  This is mainly to make sure that the main() function retains its position as the first function.  They are added in a first-in last-out fashion (a stack), so the first #include will be the last file actually imported.  Make sure your separate files do not import each other, there is no need for making infinite loops here.  If over 100 files are imported, the compiler will stop and assume there is a redundancy error.