Posted: 29th Jul 2021 17:05
Back again after almost a day of coding without interruptions.
Now, however, Im in the middle of my Level-creating program, and once more, I get stomped by the code :/

In my EDIT mode, the grid of the floor is 24x24 wooden boxes and a spawn point for my character (the Cube).
My idea was that my player could walk around and I add things to the map from his location.
Also works well, but in this last step, I need to DeleteObject (the old floor), before inserting a new one, which has a trap.
If I just Create a new box, BOTH tiles are present, which cant be good. (see image).

HOW DO I DELETE an object, which has no "ID"?



Any ideas?
Posted: 29th Jul 2021 20:29
Every object has an ID. If you don't give it one yourself, AppGameKit will give it a long ass number as ID. For your particular problem, you could code a collision routine that will return the automatically assigned ID of the object and then delete it with that ID. Or you can give each of your objects an ID yourself when you create them, which I think is the simpler solution in the end. You can set up an array for that. Or a type list. Or whatever works better for you.
Posted: 29th Jul 2021 20:35
Every object has an id, you are just not keeping track of it, which is bad practice

your grid array, turn it into a type array and store the tile id with the tile state

+ Code Snippet
Type tGrid
	id
	state
EndType
Global grid as tGrid[24, 24]

For y=1 to 24
	For x=1 to 24
		grid[x,y].id= // your object id
		grid[x,y].state= 1 // its a floor
	Next
Next


Edit:

Also, arrays are zero based, you have empty elements in your array because you are ignoring item 0

this is better
+ Code Snippet
Type tGrid
	id
	state
EndType
Global grid as tGrid[23, 23]

For y=0 to 23
	For x=0 to 23
		grid[x,y].id= // your object id
		grid[x,y].state= 1 // its a floor
	Next
Next
Posted: 30th Jul 2021 4:41
Thanks guys, that was very instructive!