Probably a very simple addressing question

Ok, I have read the “Addressing in Defold” article and still have a question.

I have a very simple demo project set up where a sprite stands on a tile map:
04%20PM

Here’s my asset pane:
14%20PM

Here’s my player.go outline:
16%20PM

In my player.script, I have this code:

function on_message(self, message_id, message, sender)
	print(message_id, message, "sender", sender, message.other_id)
	if sender == hash("player#spearCO") then
		print("Test")
	end
	
    ....

end

Basically, I am trying to determine when my spear contacts a tile, and then programmatically change the tile to something else.

From my print statement, I am getting this response:

DEBUG:SCRIPT: hash: [contact_point_response] table: 0x011b967d20 sender url: [main:/player/player#spearCO] hash: [/level]

So what I was trying to do, is if the sender is the spearCO (spear collision object) and the other_id is the /level then I would post a message to change the tile.

So what I am having trouble with is the url address of the sender:
url: [main:/player/player#spearCO]

Questions:

  • what can I put in my if-statement, to get my code to print “Test”.
  • Why is the url of the spearCO: main:/player/player#spearCO? Shouldn’t it be main:/player#spearCO? Why is there an extra ‘player’ in there?

Thanks in advance!

Hey

  1. I sugest to use collision response. The message will contain other_group that you can filter and use to detect the collision with your tilemap.
  1. About the url: ‘main’ is the collection, the first ‘player’ is probably the name you used within the ‘main’ and the last ‘player’ is your script. Then the component that send the message (spearCO). I always use something like ‘player_controller’ for the script to not get so confusing.

But this is really confusing and I don’t know if I’m right on this one.

@Dat_Indie Ahhhhh… Right. I’m sure that will solve my issue with #1. Thanks.

  1. Ok, I figured it out. I think it’s because my main.collection has a player.collection with the id player, which has a player game object… Way too confusing. I’ll have to clarify this as you suggest.

Thanks