for x = 1, 16 do
for y = 1, 16 do
local cntr = Center:new()
cntr.point = {x = 0.5 + x - 1, y = 0.5 + y - 1}
centerLookup[cntr.point] = cntr
table.insert(self.centers, cntr)
end
end
在上面的代码中,centerLookup [point]是通过输入点位置来查找相应的Center对象。我可以在for循环中声明局部变量吗?
然而,当我尝试这样做:
function neighbors(center, sqrtsize)
if center.point.y + 1 < sqrtsize then
local up = {x = center.point.x, y = center.point.y+1}
local centerup = centerLookup[up]
table.insert(center.neighbors, centerup)
end
end
centerup收益为空值
IDK如果问题是,我不能用一个表作为索引,但这是我在想什么。
有人知道这里有什么问题吗?
P.S.如果有帮助的话,中心开始为0.5(所以[0.5,0.5]将是第一个中心,然后是[0.5,1.5]等)
在此先感谢!
感谢在深入的解释,这正是我一直在试图找出 – Denfeet