gpt4 book ai didi

lua - 尝试索引字段? (零值)

转载 作者:行者123 更新时间:2023-12-04 21:22:40 25 4
gpt4 key购买 nike

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

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]

你可以通过这样做来避免这个错误:

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

相反。

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

关于lua - 尝试索引字段? (零值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com