循环表数组

时间:2019-06-30 15:39:52

标签: lua

如何循环此表数组?

TASK_CONFIG = {
    [1] = {NAME = "1-a", COUNT = 10, REWARD = 1000},
    [2] = {NAME = "4-b", COUNT = 10, REWARD = 6000},
    [3] = {NAME = "3-a", COUNT = 15, REWARD = 2400},
}

我需要类似的东西:

for each ITEM in TASK_CONFIG
    for each FIELD in ITEM
        -- do something
    next
next

这个想法是循环每个字段,例如:

环绕每一行并获取值“名称”,“计数”,“奖励”

1 个答案:

答案 0 :(得分:1)

for a, b in pairs(TASK_CONFIG) do
    for c, d in pairs(b) do
        -- print info / do something
    end
end