Let's have a look at how scripts can be used to control the progress of a game. Loops repeat when a statement is true.
|this script simply loops from the given condition
decrementing by 1 each time,
down to 0
displaying the value of test
and then exits the level.
|As long as a given condition is true, the while loop will repeat 0 or more times.
A while loop evaluates its test expression before executing the body of the loop.
Okay, so counting down for a ten count and then exiting the level may not be much of a gameplay, however, the principle is valid for many scenarios. A popular application of a while loop is to check if a certain type of monster has been completely wiped out and then something happens, like a door opens or closes, or a sector rises or lowers.
Script 1 checks if all shotgunguys with TID 10
Script 2 checks if any monster with TID 11
|A do loop is simply a while loop turned on its head.
First comes the loop, then the test expression.
|Unlike a while loop, a do loop always executes at least once.|
Again an example to do the same as before, count from 10 to 0 and end the level.
|In a for loop the initialzing test and modifying expressions are grouped
in one area, separated by a semicolon.