Lua Checkers Game Checking if Someone has Won
21:39 20 Sep 2026

I'm creating a simple checkers game in Lua that runs in the terminal. I'm trying to create a function that checks if a player has won or not. I'm not very good at programming, just so you know. Here's the functions of the context:

function tableIndexCheck(table, what)
    local i = 0
    while i < #(table) do
        i = i + 1
        if table[i] == what then
            return true
        end
    end
end

function winCheck()
    local i = 1
    local u = 1
    local blue = 0
    local red = 0
    while u <= 2 do
        while i <= 8 do
            if tableIndexCheck(grid[i], 1) then
                local blue = 1
                break
            elseif tableIndexCheck(grid[i], 2) then
                local red = 1
                break
            elseif tableIndexCheck(grid[i], 3) then
                local blue = 1
                break
            elseif tableIndexCheck(grid[i], 4) then
                local red = 1
                break
            end
            local i = i + 1
        end
        local u = u + 1
        local i = 0
    end

I have 8 grid tables that range from grid[1] to grid[8] and each of them have 8 items. Each number represents either blue or red's piece (3 and 4 represent their kings).

So what this is supposed to do is cycle through each grid row and check if it has any pieces. If it finds a blue piece, it will know that blue isn't dead. If it finds a red piece, it will know that red isn't dead. If either blue or red is dead, it's supposed to return true because that means somebody has won.

I can't figure out what's causing this issue, but it keeps repeating in a loop when I call the function and won't stop.

Thanks for taking the time to read this.

lua