So, I have an array
//loop here
nummobs = nummobs + 1
Mobs = {}
Mobs[nummobs] = Entity.Init(x(locations to spawn mob), y(locations to spawn mob),"testMob")
Then, call the draw method…
for i = 0, table.getn(Mobs) do
Mobs[i].draw()
end
Error: map.lua:54(Mobs[i].draw() line): attempt to index field ‘?’ (a nil value)… BUT IT HAS SOMETHING IN IT! right?
Anyone ever try something like this? Can anyone fix it?
Thanks
Nate
Lua uses 1-based indexes for arrays. Thus, the range of an array is
[1, n]inclusive, wherenis the number of elements.More importantly, you can use
ipairsand not have to write out the loop components:Oh, and never use
getn; use the#length operator instead.