For-loops

A "for-each loop" allows you to execute a piece of code multiple times, with it able to access and process some object in a collection each time. Megalo offers a few types of for-each loops:

for each object
Process every object on the map.
for each object with label ...
Process every object on the map that matches a given Forge label.
for each player
Process every player currently participating in the match.
for each player randomly
Process every player in a random order.
for each team
Process every team defined in the gametype, as well as Neutral Team.

For each object

This block loops over every object on the map. You can access the object being processed using current_object.

For each object with label

This block loops over every object on the map that matches a given Forge label. The label can be specified as a string literal containing the label's name, or as an integer constant denoting the index of the Forge label in the game variant's Forge label list. You can access the object being processed using current_object.

For each player

This block loops over every player currently in the match. You can access the player being processed using current_player.

For each player randomly

This block loops over every player currently in the match, in a random order. You can access the player being processed using current_player.

For each team

This block loops over every team currently in the match. You can access the team being processed using current_team.