Create a grid of objects (x,y)?

Hi there,

A standard way to create a 2 dimensional array (grid) of objects (e.g. fill out 5 rows and 5 columns) would normally be using a for condition inside of another for condition. For a 3 dimensional grid we could use for inside of a for which is inside of another for (basically as many nested for statements as there are dimensions).

What is the best way to replicate this in gdevelop?

E.g. this works to create a 1 dimensional grid of 5 objects:

(Note I noticed the wrong variable name, should be ObjectX, but this is just for example, not an actual running code).

But I’m trying to make a 5x5 matrix (2 dimensional grid), so for each of the created object at ObjectX position, I need to create 4 more objects at Y position.

Thanks in advance. :slight_smile:

in GDevelop the Repeat event works similar to For loop, to make a 5x5 grid, you could do something like this:

And the result is:
result.png

What it does basically, it create an object on the top then create 4 below and repeat this 5 times.

2 Likes

Awesome, thank you. I wasn’t sure about the order of execution in nested repeat elements. You cleared everything up. :slight_smile:

This also seems to work as a way to get rid of the “counter” condition.

It doesn’t make the code better, just very slightly smaller.

2 Likes