I'm trying to make a grid, using a table, which stores information such as x & y coordinates, texture information and another table. Here's some of the code used to creating the grid:
for i = i, n do
local random = math.floor(rainbow.random(1, 13))
self.grid[i] = {
sprite = Labyrinth:make_cell_texture(spritebatch, position_x, position_y, i, random),
y = position_y,
x = position_x,
nav = Cell:get_nav(random)
}
position_x = position_x + 0.09375
end
It's in the
nav = Cell:get_nav(random)
part that I'm creating the new table:
if random == 1 then
self.nav = {
north = true,
east = false,
south = false,
west = false,
}
The problem is accessing said variables, to check if they are true and false. I return self.nav to grid[i].nav, and I am able to print(self.nav.east) and get a true.
But accessing the table later down the line causes it always to return nil, even though I can get it to print that there is a table there.
I've tried with this loop:
for i = 1, 10 do
if self.grid[i].nav.north and self.grid[i + 10].nav.south then
print("Two sides are touching!")
end
end
Also with self.grid[i][4].north, but to no avail.
Is the way I set it up wrong? Also tried renaming nav to [4].
Am I barking up the wrong tree? Weren't tables designed to be this deep?