[solved] Missing table entry

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

[solved] Missing table entry

Post by CaptainMaelstrom »

I'm having trouble with my latest project. When I try to remove an object from my bump.lua world object, I get an error saying it hasn't been added yet -- although it has.

To replicate the error, open the game and left-click to shoot at the other object on screen. It will flash and disappear. This triggers the object's destruction which reproduces the error.

It seems like somehow between the mob:destroy() function call and the bump:remove(item) function call, world.rects table gets changed so that item is no longer an entry. What is happening and how do I fix it?

Thanks.

Edit:

I've removed stateful so now the only libraries involved should be bump and middleclass. I've also fixed the .love so that it has main.lua at the top-level.
Last edited by CaptainMaelstrom on Sat Apr 30, 2016 8:16 pm, edited 3 times in total.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: Missing table entry

Post by Vimm »

CaptainMaelstrom wrote:I'm having trouble with my latest project. When I try to remove an object from my bump.lua world object, I get an error saying it hasn't been added yet -- although it has.

To replicate the error, open the game and left-click to shoot at the other object on screen. It will flash and disappear. This triggers the object's destruction which reproduces the error.

It seems like somehow between the mob:destroy() function call and the bump:remove(item) function call, world.rects table gets changed so that item is no longer an entry. What is happening and how do I fix it?

Thanks.
unfortunately I dont have the answer cuz im bad :P I just wanted to point out that when packaging your game into a .love file, dont package the folder, select everything in the folder and add that to zip instead.
User avatar
pgimeno
Party member
Posts: 3657
Joined: Sun Oct 18, 2015 2:58 pm

Re: Missing table entry

Post by pgimeno »

I have no idea of how middleclass and stateful work, but it seems that you're not destroying the Mob instance, but the dying instance or state or whatever it is:

Code: Select all

[...]
  dying = Mob:addState('dying')
[...]
function dying:update(dt)
  [...]
  if d.timer <= 0 then
    self:destroy()
  end
end
[...]
function Mob:destroy()
  local x, y,w , h = game.world:getRect(self)
  [...]
That last line is where the error triggers. The stack dump says that it's called from the self:destroy() call in dying:update(), that I've also copied above.

Sounds like Mob:destroy() receives a 'self' that is a 'dying' table (or a descendant or an instance or something like that) rather than the main 'Mob' table (or a descendant or an instance). Since I haven't used the libraries, I don't know if you can access the main 'Mob' instance from the 'dying' table, so I can't suggest a fix.

Also, what Vimm said. I suggest you to test the .love before uploading it.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Missing table entry

Post by CaptainMaelstrom »

A piece of the puzzle that's even stranger (to me). I've tried adding the item to world.rects table from within the mob:destroy function and I get an "already added item to the world" error. But if I comment out my add, in the very next 2 function calls, it says item isn't in world.rects!

Image

It seems to me like somewhere between these two function calls, item leaves world.rects... I'm just not sure how.
User avatar
pgimeno
Party member
Posts: 3657
Joined: Sun Oct 18, 2015 2:58 pm

Re: Missing table entry

Post by pgimeno »

I'd say it's not so much a problem with adding the dying state, as it is of passing the Mob instance rather than the state.

Which I have no idea how to do. But I may be wrong. Maybe someone who understands these libraries can help better.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Missing table entry

Post by CaptainMaelstrom »

I figured it out. I wasn't removing the mob from game.mobs table in mob:destroy. "self = nil" does not prevent game from calling mob:destroy every frame. So the 2nd time it gets called, there's no item to remove from bump world.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 8 guests