"loop in gettable" when I add 100 objects to an array
Posted: Tue Oct 21, 2014 2:25 am
Whenever I add 100 instances of my class to an array it breaks when calling love.draw() when it hits 100 bullet objects added. I am removing the bullets as they leave the screen so the array size is not hitting close to 100 now but even still i get the bug.
Error: functions.lua:24: loop in gettable
stack traceback:
functions.lua:24: in function 'drawObjects'
main.lua:62: in function 'draw'
[string "boot.lua"]:438: in function <[string "boot.lua"]99>
[C]: in function 'xpcall'
Here is my class:
And here is my draw function:
The array's name is "bullets" and so I'm using this:
I have made other games using this method and have put waaaay more than 100 objects into an array without any problems. Is this a problem specific to LOVE2D 0.9.1??
Any help would be greatly appreciated.
The love file included only works with an XBOX360 pad. The sticks move and the triggers fire.
Error: functions.lua:24: loop in gettable
stack traceback:
functions.lua:24: in function 'drawObjects'
main.lua:62: in function 'draw'
[string "boot.lua"]:438: in function <[string "boot.lua"]99>
[C]: in function 'xpcall'
Here is my class:
Code: Select all
bullet = {}
-- CONSTRUCTOR
function bullet:new(playerx, playery, xd, yd)
local object = {
x = playerx,
y = playery,
xd = xd,
yd = yd,
red = 255,
redUp = false,
deleteMe = false
}
setmetatable(object, { __index = bullet })
return object
end
function bullet:update(dt)
self.x = self.x + self.xd*dt
self.y = self.y + self.yd*dt
if self.redUp then
self.red = self.red + 20
if self.red > 230 then self.red = 230; self.redUp = false end
else
self.red = self.red - 20
if self.red < 100 then self.red = 100; self.redUp = true end
end
-- CHECK BOUNDS
if self.x < -100 or self.x > 1380 or self.y < -100 or self.y > 820 then self.deleteMe = true end
end
function bullet:draw()
g.setColor(self.red, 100, 100, 255)
love.graphics.circle("fill", self.x, self.y, 7, 100)
g.setColor(255, 255, 255, 255)
end
Code: Select all
function drawObjects(obj)
for i=1, table.getn(obj) do
if obj[i] then
obj[i]:draw()
end
end
end
Code: Select all
drawObjects(bullets)
Any help would be greatly appreciated.
The love file included only works with an XBOX360 pad. The sticks move and the triggers fire.