attempt to index field ? (nil value)
12,308
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
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.
Author by
Scicare
Updated on June 04, 2022Comments
-
Scicare almost 2 years
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