2013-04-09 63 views
1

这是一个奇怪的问题,但它让我感到困惑。我希望能够在一个基于id的系统上存储x和y的合作伙伴,例如:id.1.x = 10,id.1.y = 15:id.2.x = 50,id.2.y = 42,我正试图为我做一个功能,我遇到了问题。这里是我的代码如何在Lua中为多个数据类型数组建立索引值?

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) 

我真的很疲惫,很想把这个休息,所以如果有人可以帮助它将不胜感激。

回答

3
function box(xpos,ypos,id) 
    a[id] = {x = xpos, y = ypos} 
end 
相关问题