So I am trying to insert a "cannonball" object into a "cannonballs" table, yet despite being created and inserted into the table, the object doesn't seem to be in the table.
This code is inside "Player.lua":
Code: Select all
function self.keypressed(key)
if (key == "space") then
cannonball = Cannonball.new(self.x+self.image:getWidth()/2, self.y+self.image:getHeight()/2, self.rot+90, math.random(30,35))
table.insert(self.cannonballs, cannonball)
print(#self.cannonballs)
end
end
Code: Select all
Cannonball = {}
Cannonball.new = function(x,y,dir,speed)
local self = self or {}
self.x = x
self.y = y
self.dir = dir
self.rot = 0
self.speed = speed
-- etc.
I'm fairly new to LOVE, so any tips or tricks are highly appreciated. I am also probably setting up my objects completely wrong, so if anyone could point me to a source or tutorial that explains this further would be great.
I've included the .love file if further details are needed. Be aware, it's a mess.
Thank you.