Accessing Individual Cells of a Virtual Grid

Lets say we have a top down tile based game which utilizes a virtual grid as its basis.
Now there is no way to know which cell is which one.

Lets say the game involves a text input which accepts one grid-cell’s address. (For Example “B6”, where “B” denotes the row and “6” denotes the column).

This is to , lets say we don’t want to move the player using pathfinding, or top down behavior or any other similar methods. Lets say we want to move the player entirely on the cell’s address basis. We specify the address in the text input and the player moves to corresponding cell.

How do we assign an address to cells automatically (distribution or sorting) so that they can be used for various purposes.

This is a question that may extend to ‘How to search in a sorted 2d matrix’

…but how do we implement this in Gdevelop?

I think you need to use structure variables.
You can use Repeat loops to create variables for your virtual grid, and then use dynamic access to use them.
It might be a bit of a headache though. :sweat_smile:

Much easier to set up an invisible grid and use click/touch :grin:

Agreed, I only set this example to understand how individual cells can be accessed.
In a crude way, if each cell was an instance of a 64x64 no pixel object, then each instance can be sequentially assigned a row-column number via instance variables(structure in advanced cases). Then access a particular cell via that instance variable.

1 Like