# Array bidimensional

hi, i’m in need to do something like this, but with GDevelop:

dim map(250,250)
for y=1 to 250
for x=1 to 250
map(x,y)=“the value i want”
next x
next y
a=map(rnd(250),rnd(250))

easy with a basic, crapping with GDevelop… (for me)

It looks like you want an array of arrays:

And then use map[x][y] to access the value.

And no, you won’t have to create the 250x250 cells in the editor, the image was to visualise how it is stored.

1 Like

Thanks, so the array’s index can be instanced? no need to declare all the 250x250 cells? (62500 cells…)

and what about loops… my idea is this: i’m making a top down racing game, this is the circuit:

for reading the ground under the car (white=no slow down, value of grey=slow down), i want to use this map (250x250px):

BUT: PixelRead don’t works outside the view window, so i’ve to store the data in a bidimensional array.

this is why i want to use two loops,

for y=1 to 250

for x=1 to 250

read the color at x,y and store in the array

next x

next y

i need to translate this in GDevelop. i’m working on it, but advices of more experienced user can be useful.

thanks, Ermes

Something like:

However, I would question why you’re resorting to a bit representation of the track. It would seem a better move to cut the various track into pieces according to colour/impact on speed, and created collision boxes depending on how they affected the speed.

1 Like

MrMen, great, this is exactly the conversion i was in need.

why use the colormap…

because it can be automated, i’ve only to make a greyscale from my coreldraw file of the circuit, no need to edit the various collision boxes.

so, first the routine you wrote loads in the array the values of the greyscale map.
Then, reading the array, i’ve the value of the ground type of the track without calling collisions (time spent).

thanks, really.

1 Like

Worked. fine. some trouble about timing, first i’ve to move camera, then in a second run, read pixels.

good to have readpixel, but i see is a slow routine. it take about 5 second on my pc to read 10000 pixels. no chance to improve speed? my pc is a i7 3,4 ghz with 16 gb ram.

thanks, Ermes

I’d hazard a guess that you’d be better off to do it yourself. It may be faster to just read a pixel, check it’s greyscale colour and assign a value to the array in JS (I’m assuming the extension splits each pixel into the 4 channels)

1 Like

This method of coloration/pixel reading is going to lead to very poor performance in any engine, but especially in GDevelop, since all actions occur sequentially per frame. There is no asynchronous events, so I’m not sure there is an effective way to do this.

@ErmesBertone is storing a value based on the pixel colour in an array of arrays, so the pixel read is a once-off at the start of the scene.

2 Likes

Exactly. it is an array of arrays, but visualized in a bitmap. It’s a different way to see a matrix.