【问题标题】:attempt to index field ? (nil value)尝试索引字段? (零值)
【发布时间】:2012-03-12 22:01:45
【问题描述】:

我不确定问题出在哪里。有人知道为什么吗?

function check(board, color, row, col)
--if same color, change tile to "o"

if board[row][col] == color then -- attempt to index nil?
    board[row][col] = "o"
    count = count + 1
    return "o"
end

return

结束

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    问题是board[row]没有定义;它是nil。所以你正在尝试做nil[col]

    您可以通过这样做来避免此错误:

    if board[row] and board[row][col] == color then
    

    相反。

    但是,我建议您查看板的创建方式 - 例如,确保您没有在代码中的某处错误地切换行和列。

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 1970-01-01
      • 2019-10-10
      • 2013-06-18
      • 2011-11-05
      • 2018-12-30
      • 1970-01-01
      相关资源
      最近更新 更多