Page 1 of 1

[solved] Missing table entry

Posted: Sat Apr 30, 2016 4:49 am
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.

Re: Missing table entry

Posted: Sat Apr 30, 2016 9:57 am
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.

Re: Missing table entry

Posted: Sat Apr 30, 2016 1:52 pm
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.

Re: Missing table entry

Posted: Sat Apr 30, 2016 3:03 pm
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.

Re: Missing table entry

Posted: Sat Apr 30, 2016 3:10 pm
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.

Re: Missing table entry

Posted: Sat Apr 30, 2016 8:16 pm
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.