Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
gdevelop5:events:foreach [2018/10/01 04:30]
valiant_curiosity [For Each events]
gdevelop5:events:foreach [2018/10/13 23:56]
valiant_curiosity [For Each events]
Line 3: Line 3:
 A For Each event is a kind of [[gdevelop5:​events|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. A For Each event is a kind of [[gdevelop5:​events|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 ​as conditionsActions ​will automatically run on all the objects ​(refined ​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.+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 ​ ## Examples ​
Line 9: Line 9:
 <note tip>​**See it in action!** 🎮\\ <note tip>​**See it in action!** 🎮\\
 Open these examples online.</​note>​ Open these examples online.</​note>​
 +
 +[[https://​editor.gdevelop-app.com/?​project=example://​shooting-bullets-explanation|{{:​gdevelop5:​events:​shootingbulletsexplanationexample.png?​200|}}]]
  
 * https://​editor.gdevelop-app.com/?​project=example://​shooting-bullets-explanation * https://​editor.gdevelop-app.com/?​project=example://​shooting-bullets-explanation
 +
 +[[https://​editor.gdevelop-app.com/?​project=example://​platformer|{{:​gdevelop5:​behaviors:​platformerbehavior.png?​200|}}]]
 +
 * https://​editor.gdevelop-app.com/?​project=example://​platformer * https://​editor.gdevelop-app.com/?​project=example://​platformer
  
 ## When to use it ## When to use it
  
-Consider ​this example. When the player is in 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, ​otherwise ​a single explosion would be created ​the position of the first enemy:+Consider ​the example ​below. When the player is in 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:
  
 {{ :​gdevelop5:​events:​for-each-example.png?​nolink |}} {{ :​gdevelop5:​events:​for-each-example.png?​nolink |}}