# Issues understanding 2D Array

Good day,

I am having issues understanding 2D Array, I am trying to make an 8,8 array and then populate with the numbers 64 to 1.

This is how it’s coming out at the moment.

63, 62, 61, 60, 59, 58, 57, 56,
55, 54, 53, 52, 51, 50, 49, 48,
47, 0, 46, 45, 44, 43, 42, 41,
40, 0, 0, 39, 38, 37, 36, 35,
34, 0, 0, 0, 33, 32, 31, 30,
29, 0, 0, 0, 0, 28, 27, 26,
25, 0, 0, 0, 0, 0, 24, 23,
22, 0, 0, 0, 0, 0, 0, 21,

``````local array2D = require(game.ReplicatedStorage.Modules.Array2D)
local newArray = array2D.new(8,8,0)
local count = 64 -- Populate array from 64 to 1

for x = 1, 8 do
newArray:Set(x, 1, count)
count = count - 1

for y = x, 8 do
newArray:Set(x,y,count)
count = count - 1
end

end
``````

You are very close. The error occurs in

``````for y = x, 8 do
``````

When you set `y = x` it’s only looping over `y` values of `x` to `8`, instead of the full range of `1` to `8`. The fix is to change the line to

``````for y = 1, 8 do
``````

EDIT:
Also the lines

``````newArray:Set(x, 1, count)
count = count - 1
``````

are unnecessary.

1 Like

Can you please explain what this module is?

Looks like he figured it out and replied in the wrong topic lol.

1 Like