尝试索引字段? (零值)
我不确定问题出在哪里。有人知道为什么吗?
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
结尾
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
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
board[row]
没有定义;它是nil
。所以你正在尝试做nil[col]
。您可以通过执行以下操作来避免此错误:
相反。
但是,我建议您检查板的创建方式 - 例如,确保您没有错误地在代码中的某处切换行和列。
The problem is that
board[row]
is not defined; it'snil
. So you are trying to donil[col]
.You can avoid this error by doing this:
Instead.
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.