【发布时间】:2014-12-21 17:29:04
【问题描述】:
当我尝试在 Lua 中打印 generateGrid 生成的表的值时,我得到一个 nil 值(没有错误)。为什么?它不应该返回某种displayObject 吗?我打印不正确吗?
local function generateGrid (rows, cols)
local grid = {}
local gridPointRadius = 10 -- the display size for the grid points.
local rowDist = display.contentWidth/(rows-1)
local colDist = display.contentHeight/(cols-1)
for row = 1, rows do
grid[row] = {}
for col = 1, cols do
testCircle = display.newCircle(rowDist * (row-1),
colDist * (col-1),
gridPointRadius) -- ugliness occurs with the offsets and non-zero indexes. how do you prefer use positioning with offsets, when the starting index is 1?
testCircle:setFillColor( 1,0,0,1 )
grid[row].col = testCircle -- why does this work, but grid[row][column] does not?
end
end
return grid
end
pathGrid = generateGrid(rowsForGrid, colsForGrid)
print(pathGrid[1][2])
【问题讨论】:
标签: lua coronasdk null lua-table