Find an instance's URL through collisions? [solved]

Hullo again, Defold Community~

So, this time around, I’m trying to look for an instance’s full URL through a collision script (because I can’t think of any other way to find something’s URL when there’s going to be so many of them).

I tried to use a variable to store the URL of the instance (which makes it hashed, but I think that’s fine?):

if message.other_group == hash("interactable") then
	if message.own_group == hash("center") then
		if message.enter then
			curinteract = message.other_id
		else
			curinteract = nil
		end
	end
end

Then I write code in order to give it an interacting message:

if curinteract then
	if button1 then
		msg.post(area..curinteract, "interact")
		interacted = true
	elseif interacted and not button1 then
		msg.post(area..curinteract, "interact_end")
		interacted = false
	end
end

I think the problem has something to do with not being able to find the collection that the instance is in(because the character which is in one collection is collection-factoried into existence in an area where the interactable NPC is also collection-factoried into existence), but I don’t know how to do that. Can someone help me with that?

Any help would be appreciated~~

If you have the id of a game object there is no need for the full url. You can post a message to a game object through its id:

msg.post(curinteract, "interact")

One thing to note though is that you seem to store curinteract in a global variable. This may or may not be a problem, but in general it is recommended to avoid it. You can store it on self instead:

self.curinteract = message.other_id
1 Like

Thank you for the tip~

Well, I actually store it as a local variable, but that’s a good idea too.

Ah, that usually works well!

1 Like

However, another problem comes around:

ERROR:GAMEOBJECT: Instance '/collection1/ten' could not be found when dispatching message 'interact' sent from character:/char#character_controls

The thing is, I forgot to mention that these instances are actually factory-spawned collections. Is there any way to get to the original collection through collisions?

That shouldn’t matter. The id of a game object is always unique and you should be able to use it to pay a message. Can you share a minimal example showing what it is you do?

Hello Britzl,

Isn’t it that collisions cannot occur between top-level collections? I always assumed that collection proxies called collections in as top-level but maybe that was a misconception on my part?

Is that what you are doing @ZaTimou?

Cheers,
Spen

1 Like

Yes, collisions do not happen in a situation like this, but I’ve already fixed that by using not a collection proxy but a collection factory. (I found that out in my last question over at Collection Proxy problems)

3 Likes

halp.zip (101.7 KB)

1 Like

Your example project works just fine for me:

3 Likes

That’s… strange.
It doesn’t work over here?

Nevermind I’m just being stupid. :3