For Each events

A For Each event is a kind of event that will take an object as parameter. Then, during the game, for every instance of the object, the conditions and actions will be repeated.

Usually, you don't need to use “For Each” events. Conditions and actions will automatically run on all of the objects. They are defined by their conditions. However, from time to time, “For Each” events can be useful to run an action that depends on each instance of the object.

Examples

When to use it

Consider the example below. When the player is in a collision with an object called “KillAllEnemyBonus”, we set the “life” variable of all enemies to 0. We also want to create a special kind of explosion at the position of each enemy. We need a “For Each” event to accomplish this. Otherwise, a single explosion would be created at the position of only the first enemy: