Lua - need more eyes

local ggameResourceTypes= {

    self.ggameResources= {}
    for indx,gameResourceType in ipairs(ggameResourceTypes) do
        self.ggameResources[gameResourceType]= "joe"


Why does this print 0?


Because you are creating a new table indexed by strings. The # operator only works on the numerical part of a table. So:

a = {"a","b","c"}

has #a equal to 3 as the indices default to integers, but

a = {a = "a", b = "b", c = "c"}

has #a equal to 0 as the indices are strings.

(Incidentally, to format a code block, put ~~~ either side of it, see the FAQ post for more details.)

Thank you! Wasted a whole hour train ride staring at it. Explains the failure of ipairs() as well.