我得到一个非常奇怪的索引零值错误,我无法弄清楚如何解决我的生活。这是代码:
local COLONYNUMBER = players[0].getColony()
print(COLONYNUMBER) <--- prints 0
print(colonies[0].getName()) <---- prints New Brussels
print(colonies[COLONYNUMBER].getName()) <---- ERROR HERE
答案 0 :(得分:3)
在黑暗中拍摄,但是玩家[0] .getColony()会返回字符串&#39; 0&#39 ;?因为它在lua解释器中打印为0,但肯定不会将表索引为零。我在下面谈论的例子:
local t = '0'
print(t)
-- below prints exactly the same as variable t above
local u = 0
print(u)
local temp = { [0] = true }
-- try to index into the temp table with '0'
print(temp[t]) -- undefined