Below is the code i am trying to write. I am trying to dynamically assign objects to 2d array in lua. It is returning a error saying trying index a global nil value at line grid[i][j]=diceclass.new( ((i+2)/10),((j+2)/10)) ? Is there a way to fix this or what i am trying to do possible, dynamically assigning a object to each element of the array?
local diceClass = require( "dice" )
grid={}
for i =1,5 do
grid[i]= {}
for j =1,5 do
grid[i][j]=diceclass.new( ((i+2)/10),((j+2)/10))
end
end
--dice class
local dice = {}
local dice_mt = { __index = dice }
function dice.new( posx, posy)
a=math.random(1,6)
local newdice = display.newText(a, display.contentWidth*posx,
display.contentHeight*posy, nil, 60)
return setmetatable( newdice, dice_mt )
end
return dice