日冕多维表

时间:2013-01-17 14:28:20

标签: lua corona

我正在尝试创建一个像这样的多维表

    answers = {}
for i = 1, #answers do
    answers[i] = { wrong = t[i], wrong2 = t2[i], right = t3[i]}
end

print(answers[1].wrong)

但是当我尝试访问答案[1]。错误时,我收到错误:尝试索引字段'?' (零值) 但是当我这样做时,它会为我打印

    answers = {
    {wrong = t[1], wrong2 = t2[1],right = t3[1]},
    {wrong = t[2], wrong2 = t2[2],right = t3[2]}
}
print("----------")
print(answers[1].wrong)
print(answers[1].wrong2)

为什么第一种方法不起作用?

1 个答案:

答案 0 :(得分:2)

answers = {}
for i = 1, #answers do

#answers为0.因此循环不会执行。你可能意味着#t或其他什么。