JASS Tools
News
Download
Help
JASS Manual
-------------------------------------------------------------

Statements

Each function body contains a series of statements; one statement per line. This section describes what each statement does.

Set

     set variable = expression              // (1)

     set array_variable[index] = expression // (2)

The set statement assigns a new value to a variable. In case (1), the variable is of a basic type (not an array). The expression must evaluate to a value of a type that conforms to the variable's declared type.

In case (2), the variable is an array. index may be any arbitrary expression that evaluates to an integer value, which will the the index into the array to reference. The expression must evaluate to a value of type that conforms to the array's basic type. E.G., if the variable was declared as a unit array then the expression must conform to the type unit.

Call

     call func_name(arguments)
The call statement is used to call a function (native or user-defined). arguments is a comma separated list of expressions which are passed to the function as its respective parameters. If the function is declared to take nothing as parameters, then the argument list is empty (e.g., call func_name()). The types of each argument expression must conform to the corresponding parameter type in the function's declaration. For example, a function with the prototype:
function MakeUnitsDance takes region where, integer num, 
                              string nameOfDance returns nothing

Can be called like this:

     call MakeUnitsDance(GetTriggeringRegion(), numGrunts*2, "salsa")
     // Or
     call MakeUnitsDance(myRegion, 100, MyChooseDanceFunction())
     // Etc.

The return value of the function is discarded.

If Then Else

     if predicate then
          statement
	  statement
	  ...
     elseif predicate then
          statement
	  statement
	  ...
     elseif predicate then
     ...
     else
          statement
	  statement
	  ...
     endif

An if-then-else statement is a conditional branch that spans multiple lines. In each condition block (begun with an if and ended with a endif), each predicate expression is evaluated in turn (first the one in the if, then the one in the next elseif, etc.). Each must return a boolean value. The first predicate which evaluates to true causes its associated statements to be executed (the statements in the immediately proceeding sub-block). The remainder of the statements in the other sub-blocks are ignored.

If none of the predicates return true, then the else statements are executed. There may be zero or more elseifs and the else is optional (if it is ommitted, then nothing is executed if no predicates are satisfied). For example:

     // (1)
     if predicate then
	  ...
     elseif predicate then
          ...
     endif

     // (2)
     if predicate then
	  ...
     else
          ...
     endif

     // (3)
     if predicate then
	  ...
     endif

Loop

     loop
          statement
	  statement
	  ...
     endloop

A loop statement contains a block of statements that are executed continuously. When execution reaches the end of the loop block, we return to the top of the loop and begin again.

To exit a loop block, one of the enclosed statements must be an exitwhen statement. It is legal to have an infinite loop (one that never exits; for example, a main-execution loop in an AI).

Exitwhen

     loop
          ...
	  exitwhen expression
	  ...
     endloop

The exitwhen statement is used within a loop. The expression must evaluate to a boolean value. If it evaluates to true, then execution immediately exits the inner-most loop that the exitwhen is in. The exitwhen may be within an if-then-else block inside the loop and there may be multiple exitwhens within a single loop; for example:

     local integer iterations = 10
     loop
          if DidTheThingEnoughTimes() then
               call DisplayText("Exiting Early")
               exitwhen true
          endif
          call DoSomething()
          set iterations = iterations - 1
          exitwhen iterations == 0
     endloop

Return

     return            // (1)

     return expression // (2)

The return statement causes execution to exit from the function and return to the point after it was called. If the function is declared to return a value, then the return statement must be used with an expression, which is the value that is returned to the caller. The expression must evaluate to a value that conforms to the function's declared type. There may be multiple returns within a function. All execution paths within a function must lead to a valid return (unless the function returns nothing, in which case there is an implicit return when execution reaches the end of the function).

Important Note: currently, the return value only needs to conform to the native base type of the declared return type, not the declared return type itself (E.G., if the declared type is unit, the value only needs to conform to handle). This is a bug in Blizzard's type checker. However, because this bug shows up in Blizzard's own JASS code, the current version of the syntax checker purposely contains this behavior also. You should avoid exploiting this because there is almost no scenario where it is correct.

Debug

     debug statement

Any set, call, if then else, and loop statement can be prefixed with debug. This implies the statement is only executed if an game-internal debug flag is enabled. You probably can't turn it on unless you work for Blizzard.

------------------------------------------------------------
Copyright (c) 2003 Jeff Pang
Not affiliated or endorsed by Blizzard Entertainment
SourceForge.net Logo