1

这是一个奇怪的问题,但让我感到困惑。我希望能够在基于 id 的系统上存储 x 和 y 坐标,例如:id.1.x = 10, id.1.y = 15: id.2.x = 50, id.2.y = 42,我正在尝试为我创建一个函数,但我遇到了问题。这是我的代码

a = { p = {x,y}}
function box(xpos,ypos,id)
a[id].x = xpos
a[id].y = ypos
end
box(25,30,1)
box(45,10,2)
print(a[1].x.." "..a[1].y)
print(a[2].x.." "..a[2].y)

我想打印:

25 30
45 10

但是我得到了错误:

attempt to index global '?' (a nil value)

我真的筋疲力尽,想休息一下,所以如果有人可以提供帮助,我将不胜感激。

4

1 回答 1

3
function box(xpos,ypos,id)
  a[id] = {x = xpos, y = ypos}
end
于 2013-04-09T23:08:40.140 回答