Page 1 of 1

Destroy body with Löve2D physics

Posted: Sat Feb 06, 2016 12:24 pm
by Manyrio
Hey, I am creating a sandbox game using love physics and other libaries (Light vs shadow engine v2 and videolib). I've create a map and when I place a "block", it create a new physic body but when I want to destroy one, it say me " main.lua:238: attempt to index a nil value".
I check all my code but I don't find the bug ...
(Sorry if my english is very poor, i'm french)
Here my game in .love

Re: Destroy body with Löve2D physics

Posted: Sat Feb 06, 2016 9:37 pm
by Manyrio
Here a screenshot of the game :
Image

Re: Destroy body with Löve2D physics

Posted: Sun Feb 07, 2016 8:52 pm
by ArchAngel075
been modifying the map.lua and main.lua

so many changes to make it work as expected.
I was able to make adding work, removing doesn't exactly work physics wise (but does graphically)
One major issue is you are working on globals 'stone' and 'dirt'
when you make the map, stone and dirt globals are overwritten each time a tile is made, this will result in stone and dirt globals being allllways the last overwrite.
is this intended?

also you use stone.x, stone.y which neither field exists.

Re: Destroy body with Löve2D physics

Posted: Mon Feb 08, 2016 5:18 pm
by Manyrio
Hey !
What should I do to no work on globals stone and dirt ?
I didn't thought that it was overwritte each time a tile is made, I am fixing this.
I am deleting all the stone.x an stone.y
And, can I have the code you made ? Just to see
Thank you ! And I'm new in Love2D So I am not very good :/

Re: Destroy body with Löve2D physics

Posted: Mon Feb 08, 2016 9:39 pm
by ArchAngel075
err, my method isnt well made at the moment but sure ill zip up the edited files sofar.
KEY : Search the word 'ADDED' for any additions and changes i made if you don't have code comparers.
UnviPlanet-ArchEditFiles.zip
(4.48 KiB) Downloaded 119 times
To answer immediately your questions too :
1. Stone and Dirt globals are overwritten - in my edits i made a new table map_items
there is map_items.stone, map_items.dirt
I store each tile(?) in its own location by x,y ()
I kept it to overwrite global, i just use the line 'map_items.stone[x][y] = stone' to store the changes. I believe that should work.
I just returned to Love2D myself randomly nd decided to help, so apologies if my fixes are actually terrible.

good luck!

Re: Destroy body with Löve2D physics

Posted: Tue Feb 09, 2016 6:20 pm
by Manyrio
Hey ! Really, thank you ! I am working on your code now :D