When I am trying to index my multi dimensional array inside a method. I get the error…
" Maze37: Attempt index nil with number ".
Here is the Maze Script
local Maze = {}
Maze.__index = Maze
local Cell = require( script.Cell )
local multiDemArray = require( game.ReplicatedStorage.Modules.MultiArray )
--------------------------
grid = multiDemArray.new()
--------------------------
function Maze.new( ncols, nrows , width )
local self = setmetatable( {} , Maze )
self.cols = ncols
self.rows = nrows
for i=1, self.cols do
for j=1, self.rows do
local Cell = Cell.new( i , j , width )
Cell:Show()
grid[i][j] = Cell
end
end
return self
end
function Maze:Update()
grid[ math.random( self.cols ) ][ math.random( self.rows ) ].Part.BrickColor = BrickColor.new("Crimson")
end
--------------------------
return Maze
And here is my module for creating the multi dimensional array…
local dimensionalTable = {}
dimensionalTable.__index = function(table, index)
if rawget(table, index) == nil then
rawset(table, index, setmetatable({}, dimensionalTable))
end
end
dimensionalTable.new = function()
return setmetatable({}, dimensionalTable)
end
return dimensionalTable
Can someone please explain to me what I’m doing wrong here because I cant see anything??