以下は、私が書こうとしているコードです。lua でオブジェクトを 2 次元配列に動的に割り当てようとしています。行 grid[i][j]=diceclass.new( ((i+2)/10),((j+2)/10)) でグローバル nil 値をインデックスしようとしているというエラーが返されますか? これを修正する方法や、配列の各要素にオブジェクトを動的に割り当てる方法はありますか?
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