Advanced RMS: Part 3 – Control Statements

By Matei of Woad Creations
created 9/10/03

Often, you want your script to do different things in different cases, or to repeat a task twice. This is useful if you want to place an object 5 times for every player, or you want to do different things depending on which enviromnent you’ve randomly chosen, or you want to give players different units if they’re different civilizations. The AoM scripting system provides the following control flow statements:

if ( <boolCondition> ) {
       <code>
}
[ else {
       <code>
} ]

while ( <boolCondition> ) {
      <code>
}

for ( <varName> = <initialValue>;
 <comparison> <compareValue> ) { 
       <code>
}

Note that the right brackets (“[” and “]”) here mean that a part of a statement is optional.

The main difference from other programming languages is the “for” loop. The “for” loop in AoM’s RMS system is limited to using an integer value. For example, after declaring an int i somewhere in the program, you might write for(i=1; <cNumberPlayers) to repeat some code for each player number (note that cNumberPlayers includes gaia, so we don’t write <= cNumberPlayers).

A quick note: if you have only one statement between the curly brackets after an if, else, for, or while, you can omit them. So for example you can write if(i==1) i=0; instead of writing if(i==1) { i=0; }. This sometimes makes code shorter and more elegant.

In general, loops and other control statements can save you much typing and make your script shorter and more powerful.

Back to the RMS Section