(Solved) Nested objects into a collection...how do address them?

I’m a bit confused. I have a single square tile with a collision object.
And that tile has a script attached to it called single_tile.

That tile is then put into several tiles to make up a polyomino (tetris shape) as a collection.

What I don’t understand is how do I send a message to an individual tile? When I put this statement in the init function of the single_tile script

print(msg.url())

statement in the single_tile script it gives me a generic line for the entire collection like this:

|DEBUG:SCRIPT: Single Tile URL: |url: [main:/collection2/single_tile_garden#single_tile]|

I get one for each tile, but it’s the exact same message so the counter increases on the left. I spawn 3 polyominos at one time so it gives me 3 statements when I start the scene. With a count that matches the #of tiles for each polyomino (This is an edit to make it more clear).

DEBUG:SCRIPT: Single Tile URL: 	url: [main:/collection0/single_tile_garden#single_tile]
DEBUG:SCRIPT: Single Tile URL: 	url: [main:/collection1/single_tile_garden#single_tile]
DEBUG:SCRIPT: Single Tile URL: 	url: [main:/collection2/single_tile_garden#single_tile]

So the only thing I know is it’s part of collection2. But I don’t have a clue which tile it is.

The real reason I have this issue is when the single_tile has a collision with another tile I want to delete it. And it appears to be random on whether it is deleted or both are deleted or nothing happens.

That doesn’t sound right. What does the code look like in single_tile.script?

Thanks for the response. Here’s the code. And two videos showing a couple of the issues.
Also here’s the print statement. I had to screenshot it so you can see it prints the same line multiple times…one per tile. But there is no way for me to single out that tile via messaging.
image

function init(self)
	print("Single Tile URL: ", msg.url())
	msg.post(".", "acquire_input_focus")
	self.delete_me = false
	self.dragging = false
	msg.post("#collisionobject_tile", "enable")

end

function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") and message.other_id == hash("/tilemap") then
		print("Trigger Response and /tilemap...message.enter = ", message.enter)
		pprint(message)
		if message.enter then
			self.delete_me = true
			print("TRUE")
		else 
			self.delete_me = false
			print("FALSE")
		end
	elseif message_id == hash("trigger_response") and message.other_group == hash("tile") then
		print("Trigger Response and tile...message.enter = ", message.enter)
		if message.enter then
			self.delete_me = true
			print("TRUE")
		else
			self.delete_me = false
			print("FALSE")
		end
	end
end 

function on_input(self, action_id, action)
	if action_id == hash("touch") then
		if action.released and self.delete_me then
			msg.post("#collisionobject_tile", "disable")
			print("delete tile: ", msg.url())
			print("dragging: ", self.dragging)
			--if self.dragging then 
				go.delete()
			--end
		elseif action.pressed and self.delete_me == false then
			self.dragging = true
			msg.post("#collisionobject_tile", "enable")
		end
	end
end

function final(self)
	msg.post(".", "release_input_focus")  -- Release input focus when the object is deleted
end


On a side note: I love this forum’s tools and format. Kudos to whoever manages this.

It’s mostly a derivation of the popular Discourse template: https://www.discourse.org/

2 Likes

I think I need a minimal version of your project to understand what’s going on. Can you please share it (you can also email bjorn@defold.se)

I just emailed it. Please let me know if you didn’t receive it.

1 Like

Thanks. I took a look and was at first as confused as you. After playing around with it a bit I realised that the path was too long and the numeric index at the end was removed. If you count the number of characters in “/collection0/single_tile_garden1” you see that there are 33, and it seems like the msg url path limit is currently set to 32…

I haven’t looked into exactly where and how we trim the path (@JCash may know), but if you change the game object name to something shorter, for instance “single_tile1” it will work for you.

1 Like

THANK YOU! And do you ever get a day off? But I love your dedication.

BTW: I did make the change you suggested and it works.

1 Like