# ERROR:GAMEOBJECT: Instance '\<unknown\>' could not be found when dispatching message 'add\_score' sent from main:/instance0#coin (SOLVED)

**URL:** <https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268>\
**Category:** Questions\
**Created:** [October 17, 2018, 8:21am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268 "2018-10-17T08:21:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 8:21am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/1 "2018-10-17T08:21:10Z")

</div>

Hey guys! Once again I’m stuck and feel stupid trying to modify the runner tutorial sorry for bordering (once again) 😅

I’m trying to get a simple score counting for the coins to work but am getting the ERROR message:

> ERROR:GAMEOBJECT: Instance ‘\<unknown\>’ could not be found when dispatching message ‘add\_score’ sent from main:/instance0#coin

The scripts working in this case are the coin.script and the gui.gui\_script.

My coin.script currently looks like this:

```lua
local score = 1000	--punkte pro gesammelter Einheit
local speed = -240	--Geschwindigkeit des Sterns

function update(self, dt) -- funktion bestimmt x.pos der Instanz, 
	local p = go.get_position()
	p.x = p.x + speed * dt
	if p.x < -32 then --wenn sie kleiner als -32 ist (vermutlich breite des Obj.)
		go.delete() --wird Instanz gelöscht
	end
	go.set_position(p) -- ansonsten wird pos.x gesetzt
end

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then -- wenn es eine collision gibt
		msg.post("blubb#main", "add_score", {amount = score}) -- wird an blubb.go#gui script gesendet, es soll function add_score ausführen (amount ist der oben definierte score)
		go.delete() -- coin/instanz wird gelöscht
	end
end

```

My gui.gui\_script like this

```lua
function init(self)
	self.score = 0
	self.score_node = gui.get_node("score")
end

--function add_score(self, score, message)

function on_message(self, message_id, message, sender)

	if message_id == hash("add_score") then

		self.score = self.score + message.amount
		gui.set_text(self.score_node, tostring(self.score))
	end
end

```

The main.gui is attached to the game object blubb.go and only has the gui.gui\_script attached to it, a text node for the score (with the Id score) and a font.

Since the coins disappear once they collide with the hero I figure the collision response works fine. As for the instance I have no idea what it could be that’s missing. 😑  
Thanks a lot in advance! 😊

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [October 17, 2018, 8:29am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/2 "2018-10-17T08:29:07Z")

</div>

From the error message it seems like the line

`msg.post("blubb#main", "add_score", {amount = score})`

is the offender. More specifically the url “blubb#main”.

From the looks of it you are trying to send the message to component “main” on the gameobject “blubb”, is that correct? Can you post a picture of you collection outline?

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 8:35am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/3 "2018-10-17T08:35:17Z")

</div>

It should be… currently looks likte this

 ![screenshot01](https://forum-defold.b-cdn.net/uploads/default/original/2X/7/7ebbd22ebc877d8a915a140a4f54fb020cf7d5aa.jpeg)

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [October 17, 2018, 8:57am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/4 "2018-10-17T08:57:48Z")

</div>

Your gui component has id “gui” and the gui resource is named “main.gui”. Looks like the correct URL should be “blubb#gui”. A component’s URL should be visible in the editor properties outline when selected.

 ![50](https://forum-defold.b-cdn.net/uploads/default/original/2X/4/4a2e27fea1c83dc68dc7491e330442836308b241.png)

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 9:07am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/5 "2018-10-17T09:07:39Z")

</div>

changing the code of the msg.post to

```
msg.post("blubb#gui", "add_score", {amount = score})
msg.post("#gui", "add_score", {amount = score})

```

both didn’t work… the ERROR message stays the same too

In my case the url for the gui looks like this 🤨

 ![screenshot02](https://forum-defold.b-cdn.net/uploads/default/original/2X/1/11df0ba1028ab88740f2682dbba7820082a9893f.jpeg)

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:20am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/6 "2018-10-17T09:20:54Z")

</div>

Is the collection in the outline screenshot your main collection?

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:21am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/7 "2018-10-17T09:21:43Z")

</div>

> [@froghunter](#):
>
> In my case the url for the gui looks like this 🤨

The url you see in the editor is always relative to the currently open file.

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 9:23am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/8 "2018-10-17T09:23:45Z")

</div>

! It actually wasn’t but… in the main Collection it looks just the same … now I’m confused

 ![screenshot03](https://forum-defold.b-cdn.net/uploads/default/original/2X/1/1a0fff46e3bf7bd89d7b7430df036c946da22630.jpeg)

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:26am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/9 "2018-10-17T09:26:58Z")

</div>

Since “blubb” is located in “level” it gets a runtime id of “/level/blubb”. This is the absolute path to the game object. Since spawned coins always end up in the root of the game world, you can address “blubb” as either absolute (“/level/blubb”) or relative to the location (the world root) which is “level/blubb”.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:34am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/10 "2018-10-17T09:34:35Z")

</div>

> [@froghunter](#):
>
> in the main Collection it looks just the same

There is an issue on the url help in the editor. [Components report wrong url when referenced from go file in sub-collection · Issue #747 · defold/editor2-issues · GitHub](https://github.com/defold/editor2-issues/issues/747)

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 9:35am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/11 "2018-10-17T09:35:32Z")

</div>

Okay so if I get it now the msg.post should look like this:

```
msg.post("level:blubb#gui", "add_score", {amount = score})

```

It’s still not working but the ERROR message changed to

```lua
ERROR:SCRIPT: /level/coin/coin.script:15: Could not send message 'add_score' from 'main:/instance0#coin' to 'level:blubb#gui'.
stack traceback:
	[C]: in function 'post'
	/level/coin/coin.script:15: in function </level/coin/coin.script:13>

```

I can’t tell ift that’s better or worse 😅

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:39am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/12 "2018-10-17T09:39:32Z")

</div>

No.

```lua
msg.post("level:blubb#gui", "add_score", {amount = score})

```

Now you are trying to address the world “level”. This implies that you have loaded it by a collection proxy which you have not.

You should write the path to the game object as “level/blubb”. There should be no colon. So:

```lua
msg.post("level/blubb#gui", "add_score", {amount = score})

```

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:45am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/13 "2018-10-17T09:45:17Z")

</div>

The url format is like this:

`"world:/path/to/gameobject#component"`

Usually you want to address relative to where you are but you can be as specific as you want:

`"#another_component"` - address a component within the same game object.

`"gameobject#component"` - address a component in a game object in the same collection as the one doing the addressing (both are in main.collection, for instance).

`"path/to/gameobject#component"` - address a component in a game object in a subcollection relative to the one doing the addressing.

`"/path/to/gameobject#component"` - address a component in a game object in a subcollection starting from the root of the currently loaded game world (usually main.collection that is autoloaded at game start).

`"world2:/path/to/gameobject#component"` - address a component in a game object in a subcollection starting from the root of another loaded game world (loaded via proxy).

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 9:48am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/14 "2018-10-17T09:48:38Z")

</div>

😓 Okay that makes sense… the / is used wenn following a path an the # to the final object. An I don’t Need the : unless I’m having another game world from wich I want to load something  
I think I’m getting it now 🐸  
And holly maccaroni it’s working 😮 Thank you! 😍

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 17, 2018, 9:50am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/15 "2018-10-17T09:50:52Z")

</div>

Yeah, it’s sort of like directory paths on disk but you can only go down. There is no way to address stuff above the current collection (like you can with “..” in directory paths). In that case you have to start from the root.

[Addressing in Defold](https://www.defold.com/manuals/addressing/) has all the details.

---

<div class="post-metadata">

**Author:** ![froghunter](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@froghunter](https://forum.defold.com/u/froghunter)\
**Post date:** [October 17, 2018, 9:53am UTC](https://forum.defold.com/t/error-instance-unknown-could-not-be-found-when-dispatching-message-add-score-sent-from-main-instance0-coin-solved/32268/16 "2018-10-17T09:53:21Z")

</div>

Thanks! that helps a lot 😀
