我创造我的地图模块称为映射的LUA表对象,这个函数创建一个新的实例:为什么我的lua表格对象是空的?
function Map:new (o)
o = o or {
centers = {},
corners = {},
edges = {}
}
setmetatable(o, self)
self.__index = self
return o
end
,并在我的岛模块,我把这段代码中的第几行:
local map = require (*map module location*)
Island = map:new()
,当我打印中心,角落和表的数量,他们都站出来为0
我有单独的模块角:新的(),中心:新的(),与边缘:新的( )
为什么中心,角点和边缘的长度输出为0?
编辑:
这是我输入到中心表例如(四角和边缘是相似的)
function pointToKey(point)
return point.x.."_"..point.y
end
function Map:generateCenters(centers)
local N = math.sqrt(self.SIZE)
for xx = 1, N do
for yy = 1, N do
local cntr = Center:new()
cntr.point = {x = 0.5+xx - 1, y = 0.5+yy - 1}
centers[pointToKey(cntr.point)] = cntr
end
end
return centers
end
大小始终是一个完美的正方形
'map:new()'返回一个带有“转角”键的表格,指向空表格。为什么你会期望尺寸与零不同? – GoojajiGreg
在检查“Island.corners”中的元素数量之前,你正在做'table.insert(Island.corners,Corner:new())'吗? – GoojajiGreg
@GoojajiGreg再次检查,我明白你的意思,所以我深入一点。对不起,混淆 – Denfeet