Solved. How to delete an object that is not the one being dragged/dropped?

Ok, I have polyominos. Each tile has it’s own collisionobject on it. I’m using a trigger. I also have a tilemap where if it lands on certain objects the tile in the polyomino gets deleted when released. This is working perfectly.

However, my issue is I want to be able to drop the polyomino onto another polyomino. And then delete the one that is already laid down. Not the entire polyomino but just the tiles that are overlapped.

The issue appears to be the first one to send the mesasge wins OR they both send the message and they both get deleted. Or random tiles will be deleted.

My current setup is as follows:
group: bottom_tile
Mask: tile, top_tile

Upon drag I change the group to top_tile:

local function make_collision_group_top(self)
	self.dragging = true
	physics.set_group("#collisionobject_top_tile", "top_tile")
	print("make top tile: ", physics.get_group("#collisionobject_top_tile"))
end

Then on drop I reset it back to bottom_tile:

local function reset_collision_group(self)
	physics.set_group("#collisionobject_top_tile", "bottom_tile")
	print("reset tile: ", physics.get_group("#collisionobject_top_tile"))
end

It appears the trigger doesn’t reliably work for enter and exit. I have it printing statements and it will show it entering but not exiting. Sometimes if I touch two square tiles at once by sliding in sideways…it will capture both trigger events. But then when I slide away it will only report one trigger exit event.

Here’s my current on_message if statements:

	if message_id == hash("trigger_response") then 
		--pprint(message)
		if message.own_group == hash("top_tile") and message.other_group == hash("tile") and message.enter then
			self.delete_me = true
		elseif message.own_group == hash("top_tile") and message.other_group == hash("tile") and message.enter == false  then
			self.delete_me = false
		elseif message.own_group == hash("top_tile") and message.other_group == hash("bottom_tile") and message.enter then
			self.delete_other = message.other_id
			self.delete_me = false
			print("delete other one: " , message.other_id)
		elseif message.own_group == hash("top_tile") and message.other_group == hash("bottom_tile") and message.enter == false  then
			self.delete_other = nil
			self.delete_me = false
			print("Make other NIL")
		end
	end

One more odd thing. I have to put both bottom_tile and top_tile in the mask to make the trigger work on that portion of code. The first two if statements work great as “tile” is an object on my tilemap (like rocks) that I want to delete the poly tile. Once again those triggers are perfect and everything is great. I just can’t get the way to make it delete the bottom (already laid) poly tile reliably.


I think I mostly have this solved, but still it’s janky. Apparently when I’m dropping the tiles it’s not resetting back to bottom_tile group. So if I check for Top_tile with top_tile and self.dragging = true it gets me there.

There are still some strange scenarios where an odd one gets deleted but that’s probably a different issue (I hope).

I really have a tough time debugging collisions in defold…I wish there was a better way.

if message_id == hash("trigger_response") then 
		if message.own_group == hash("top_tile") and message.other_group == hash("tile") and message.enter then
			self.delete_me = true
		elseif message.own_group == hash("top_tile") and message.other_group == hash("tile") and message.enter == false  then
			self.delete_me = false
		elseif message.own_group == hash("top_tile") and message.other_group == hash("bottom_tile") and message.enter then
			self.delete_other = message.other_id
			self.delete_me = false
		elseif message.own_group == hash("top_tile") and message.other_group == hash("top_tile") and message.enter == false and self.dragging then
			self.delete_other = nil
		end

I resolved this by not using the function to change the group name on the object being dragged