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.
[solved] Missing table entry
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
[solved] Missing table entry
Last edited by CaptainMaelstrom on Sat Apr 30, 2016 8:16 pm, edited 3 times in total.
Re: Missing table entry
unfortunately I dont have the answer cuz im bad 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.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.
Re: Missing table entry
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:
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.
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)
[...]
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.
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
Re: Missing table entry
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!
It seems to me like somewhere between these two function calls, item leaves world.rects... I'm just not sure how.
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
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.
Which I have no idea how to do. But I may be wrong. Maybe someone who understands these libraries can help better.
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
Re: Missing table entry
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 8 guests