When I do print(board[x]) is returns nil, which it shouldn’t. As you can tell from the print, x is 2, and board has 7 tables. Soooo, board[2] should return a valid table.
--// Check if position is available
local function Check(board, x)
print(x) -- 2
print(board) -- table
for i = 1, y do
print(board[x]) -- nil
print(board[x][i]) -- error
if board[x][i] == nil then -- EMPTY SLOT
print("THIS POSITION IS FREE/EMPTY")
break
end
end
end
2
▼ {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {},
[6] = {},
[7] = {}
}
nil
attempt to index nil with number
Basically, when people join, I generate a table for each game
--// Generate the board
local function GenerateBoard()
local Board = {}
for i = 1, x do
table.insert(Board, {})
end
return Board
end
--// Generate the game
local function GenerateGame(board)
Games[board] = {
Seat1 = nil,
Seat2 = nil,
Turn = 1,
InProgress = false,
Board = GenerateBoard()
}
return Games[board]
end
So that’s why at the top ‘Board.Board’ is written like that.