Repeat
Repeat Loops¶
Repeat Forever loops use the repeat
keyword:
Repeat Multiple loops use the repeat
keyword followed by the number of times it should repeat wrapped in parentheses:
to
keyword:
For Loops¶
For loops use the for
keyword and come in two types, on
and in
.
On Loops¶
For loops using the on
keyword are used to access Repeat actions like Repeat On Path
and Repeat Adjacently
. Their syntax is as follows:
Adjacent
Grid
Path
Range
Sphere
for (line l on Path(attacker.EyeLocation,victim.Location)) {
allPlayers:DisplayParticleEffect(par("Flame"));
}
In Loops¶
For loops using the in
keyword are used to iterate over lists and dictionaries. Their syntax is as follows:
line data = {
"key" = "value",
"apples" = "oranges"
};
for (line k, line v in line data) {
default:SendMessage(line k, line v);
}
for (line particle in [par("Flame"),par("Cloud")]) {
allPlayers:DisplayParticleEffect(default.Location,line particle);
}
In order for variables of an unknown type to be iterated over, they must have their type manually specified using a Type Override. Additionally, the types of the variables to the left of the in
keyword can also have their types overridden.
While Loops¶
While loops use the while
keyword followed by a condition wrapped in parentheses:
For information on how to write conditions, see Conditional Expressions. Note that player
and entity
targets must be used in order to access if player or if entity conditions.