I have 2 different 2d Arrays set up in lua. The first loop
bubbleMat = {} --Set Up Table called bubbleMat
for i = 1, 10 do
bubbleMat[i] = {} --1D table with 10 components
for j = 1, 13 do
bubbleMat[i][j] = bubbleClass.new( (i*62) - 62, (j*62) - 62 ) --2D Table with 10x13 Matrix each cell given a coordinate as it is iterated through the loop
end
end
With this array i can print value of any position in the array to the console with
print(bubbleMat[x][y])
for whatever numbers of x and y
The second array for some reason does not work. The second array is as follows
bubbleMat = {} --Set Up Table called bubbleMat
for j = 1, 13 do
for i = 1, 10 do
bubbleMat[i] = {}
--bubbleMat[i][j] = {}
if j%2 == 0 then
bubbleMat[i][j] = bubbleClass.new( (i*62) - 31, (j*62) - 62 )
else
bubbleMat[i][j] = bubbleClass.new( (i*62) - 62, (j*62) - 62 )
end
end
end
print(bubbleMat)
I am unsure why I cannot index the second array
this is the following error I get in the console
attempt to index field '?' (a nil value)
Thanks in advance for any help.
Basically i want to display a grid of bubbles stored in a 2d array in the following pattern
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
as opposed to having the bubbles in the next line positioned directly underneath
Loop
for jis outside and loopfor iis inside. This is not necessarily false, but unusual.However,
bubbleMat[i]is initialized to{}in the innermost loop, which is clearly wrong.Either move that initialization into the outermost loop, or use this syntax :