3

我的 lua 代码中有以下功能。我收到一个错误Attempt to call field 'insert' (a nil value)

我有上面的主要块

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
4

1 回答 1

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]: ?
于 2013-05-07T04:19:11.393 回答