Code: Select all
function Projectile:onCollisionEnter(object, contact)
self.body:destroy()
end
Sorry for being clueless and new, but how do I fix this?

Code: Select all
function Projectile:onCollisionEnter(object, contact)
self.body:destroy()
end
What's a .love?davisdude wrote:Hi, welcome to the community!
Sorry, but we can't help you without more information: a .love would help.
As for my guess, you're trying to access it after you've destroyed it. This is like trying to access a variable you're already "nilled". You need to check whether the variable still exists before you access it.
Code: Select all
Projectile = mg.class('Projectile', mg.Entity) -- Name of class. Type = entity
Projectile:include(mg.PhysicsBody) -- Bitch got physics
Projectile.static.enter = {'Solid'}
function Projectile:init(world, x, y, settings, bdirection)
mg.Entity.init(self, world, x, y, settings)
self:physicsBodyInit(world, x, y, settings)
self.animation_state = 'idle'
bd = bdirection
self.idle = mg.Animation(love.graphics.newImage('resources/particles/bullet.png'), 6,6,0)
if true then
self.body:setLinearVelocity(1000, -100)
end
--if then
-- self.body:setLinearVelocity(-1000, -100)
--end
end
function Projectile:onCollisionEnter(object, contact)
end
function Projectile:draw()
self:physicsBodyDraw()
self[self.animation_state]:draw(
self.x - self[self.animation_state].frame_width/2,
self.y - self[self.animation_state].frame_height/2 - 2)
end
I don't know how to destroy the object, I just want the entire object, body, everything - removed from the game when it hits a wall.ArchAngel075 wrote:
anyhow, the point made is : is the Projectile object also destroyed and any attempt to draw it stopped(as it shouldnt exist anymore) or is there perhaps something somewhere still calling the function that draws the object?
Code: Select all
if not theBody then print("Body is null") ; return end
I'm not using anything to store the projectiles. I guess that's the problem, I don't have an identifier on any of the projectiles.ArchAngel075 wrote:right...
Im having trouble following the code, never worked with mogamett before. To help direct me, tell me the file, line number(if possible) and line of code(s) you change to cause the body to be destroyed, also where do you store the reference to the projectiles upon their creation? ie, do you use a single database or a player.projectiles table etc. If i know where this is i know what to nil more or less on body:destroy()
its just so much files to sift through haha...
Code: Select all
function Projectile:onCollisionEnter(object, contact)
--self.body:destroy()
end
Users browsing this forum: Ahrefs [Bot] and 5 guests