gol.lua:17: attempt to index field '?' (a nil value)

Started by TheTinyDeskEngineer, Aug 19, 2021, 12:56 am

Previous topic - Next topic

TheTinyDeskEngineer

Pastebin: X7K6ekPE

I'm trying to recreate Conway's Game Of Life in Computercraft, and I've gotten the part of drawing cells onto a grid working fine, but when I press Enter to start the simulation it gives me this error.

I used Notepad to search for question marks, but it can't find any.

The line it refrences (and the ones before and after it) are:
Code Select
    for i = 1, #offsets do
        if grid[offsets[i][1]][offsets[i][2]] ~= nil then
            count = count + grid[offsets[i][1]][offsets[i][2]]

Lupus590

The question mark means that Lua couldn't figure out the name of the variable that was being indexed. Put another way, one of the tables that you are indexing is nil, unfortunately, you have several tables (including those within other tables) on that line so it's going to be a bit of a pain to pick through and find out what is nil.