the error appears when i run this code the second time, but not the first (everything prints corrrectly)
local function renderlevel(self) -- this creates all the tiles, dudes, trees, star, and spaces.
print(55)
self.wait = 0
self.dudepos= {}
self.dudegos= {}
self.dudestarts= {}
self.allgos = {}
print(61)
self.gridsize = (math.sqrt(#self.level))
pprint(self.level)
print(63)
for k, v in ipairs(self.level) do
local x = ((k-1)%self.gridsize)
local y = self.gridsize-(((k-x)/self.gridsize)+1)
local z = 0
local pos = vmath.vector3((x*self.tilesize)-(self.tilesize*self.gridsize)/2,(y*self.tilesize)-(self.tilesize*self.gridsize)/2,z)
local rot = vmath.quat(0,0,0,0)
print("72")
if v == 0 then --render space (useful for those cute corners)
local ids = collectionfactory.create("#space", pos, rot)
local map_id = ids[hash("/go")]
table.insert(self.allgos, map_id)
go.set_parent(map_id, ".")
elseif v > 0 then --render tile
pos.z = -0.5
local ids = collectionfactory.create("#tile", pos, rot)
local map_id = ids[hash("/go")]
table.insert(self.allgos, map_id)
go.set_parent(map_id, ".")
if v == 2 then
pos.z = 0.2
local ids = collectionfactory.create("#dude", pos, rot)
local map_id = ids[hash("/go")]
table.insert(self.allgos, map_id)
go.set_parent(map_id, ".")
table.insert(self.dudepos, k)
table.insert(self.dudegos, map_id)
table.insert(self.dudestarts, k)
elseif v == 3 then
local ids = collectionfactory.create("#tree", pos, rot)
local map_id = ids[hash("/go")]
table.insert(self.allgos, map_id)
go.set_parent(map_id, ".")
elseif v == 4 then
local ids = collectionfactory.create("#star", pos, rot)
local map_id = ids[hash("/go")]
table.insert(self.allgos, map_id)
go.set_parent(map_id, ".")
end
end
end
print("107")
end