如何迭代字典/文本框表?

Ale*_*tto 1 lua moai

我有一个文本框表,其中键是位置的名称(topRight,topLeft ...).

一次创建和配置一个工作正常:

kanaAt = {}
function startKanas ()
    kanaAt.topLeft = MOAITextBox.new()  
    kanaAt.topLeft:setFont(font)
    ...
    kanaAt.topLeft:setString("?")
    layer:insertProp (kanaAt.topLeft)

    kanaAt.topRight = MOAITextBox.new()
    kanaAt.topRight:setFont(font)
    ...
    kanaAt.topRight:setString("?")
    layer:insertProp (kanaAt.topRight)
end
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试迭代它时,不是这样:

kanaAt = {}
function startKanas ()
    kanaAt.topLeft = MOAITextBox.new()
    kanaAt.topRight = MOAITextBox.new() 
    kanaAt.bottomLeft = MOAITextBox.new()
    kanaAt.bottomRight = MOAITextBox.new()          

    for name, text in ipairs(kanaAt) do
        text:setFont(font)
        text:setTextSize(90,60)
        text:setYFlip(true)
        text:setRect(-50,-50,50,50)
        layer:insertProp (text)
    end

    kanaAt.topLeft:setString("?")
    kanaAt.topLeft:setLoc(-325, 225)
    kanaAt.topRight:setString("?")
    kanaAt.topRight:setLoc(325, 225)
    kanaAt.bottomLeft:setString("?")
    kanaAt.bottomLeft:setLoc(-325, -225)
    kanaAt.bottomRight:setString("?")
    kanaAt.bottomRight:setLoc(325, -225)

end
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

Ego*_*off 5

使用pairs()而不是ipairs().