Lua attempt to index ? (a nil value)

lua
10,012

shot in the dark, but does players[0].getColony() return the string '0'? because that'd print out in the lua interpreter as 0, but would definitely not index into the table as zero. example of what i'm talking about below:

local t = '0'
print(t)
-- below prints exactly the same as variable t above
local u = 0
print(u)

local temp = { [0] = true }
-- try to index into the temp table with '0'
print(temp[t]) -- undefined
Share:
10,012
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin over 1 year

    I am getting a really strange indexing a nil value error that I cannot figure out how to solve for the life of me. Here's the code:

    local COLONYNUMBER = players[0].getColony()
    print(COLONYNUMBER) <--- prints 0
    print(colonies[0].getName())  <---- prints New Brussels
    print(colonies[COLONYNUMBER].getName()) <---- ERROR HERE