本文介绍了尝试索引字段? (零值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am not sure where the problem is. Anyone know why?

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

结束

推荐答案

问题是未定义board[row];是nil.因此,您正在尝试执行nil[col].

The problem is that board[row] is not defined; it's nil. So you are trying to do nil[col].

您可以通过执行以下操作来避免此错误:

You can avoid this error by doing this:

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

相反.

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

However, I'd recommend you to review the way board is created - for example, make sure that you have not switched rows and cols somewhere in your code by mistake.

这篇关于尝试索引字段? (零值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 09:50