我的lua代码中有以下功能。我收到错误Attempt to call field 'insert' (a nil value)
我在主要的chunck
上面local cardDeck;
local suits = {"h","d","c","s"};
然后在功能
function createDeck()
cardDeck = {};
for i=1, 4 do
for j=1, 13 do
local tempCard = suits[i]..j;--PRINT SHOW VALID VALUE HERE i.e. "h1","d2" etc
table.insert(cardDeck,tempCard); --THIS LINE IS ERROR
end
end
end
答案 0 :(得分:4)
您确定自己没有在程序的其他地方定义table
吗?
> table.insert({},1)
> table = {}
> table.insert({},1)
stdin:1: attempt to call field 'insert' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?