2
votes

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
1
Is it the number 0 or a string "0" in COLONYNUMBER? - Etan Reisner

1 Answers

3
votes

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