Trouble sending messages between collections (SOLVED)

Hey,
So I have a situation where I have a main menu and a level select. I have got it so that when you click play it takes you to the level select, this is working fine using a msg.post to a controller script. The problem occurs when I try to go back to the main menu, I am using the same receiver url from the main menu to controller as from level select to controller. The only difference is that the controller and main menu are in the same collection whereas the controller and level select are in different collections. The 2 collections are Main.collection and Level Select.collection. The error message I get is:

ERROR:GAMEOBJECT: Instance ‘/Main’ could not be found when dispatching message ‘main menu’ sent from default:/go#Level Select

Is there something else I have to add to the receiver url when addressing a script in a different collection?

Remember to set the name of your collection in the Outline view:
Screenshot_6
Also, please post your code when asking questions. In this case, it’d be helpful to see how you call msg.post().

2 Likes

Hey there!
I think you’re having problem to send messages between game worlds. This will help:

Here is the code sending the message:

if action_id == hash("touch") and action.pressed then
		local button = gui.get_node("Exit")
		if gui.pick_node(button, action.x, action.y) then
			msg.post("/Main#Main", "main menu")
		end
end

Here is the code receiving the message main menu:

if message_id == hash("main menu") then
msg.post("/Main#Main Menu", "enable")
msg.post("/Main#Level Select", "unload")

I still get this error when I run the program:

ERROR:GAMEOBJECT: Instance ‘/Main’ could not be found when dispatching message ‘main menu’ sent from default:/go#Level Select

Both the collections involved are named Main and Level Select

Any help would be appreciated.

To send a message to another collection:

msg.post("[Collection name]:/[GO name]#[Component name]")

e.g.

msg.post("level1:/go#sprite")

It also looks like you still haven’t changed the collection name in the Outline view:

Thank you, it now works perfect, I just needed the extra Main at the start.
I had named the collection just did not add it to the start of the code.