I can't switch to another collection (SOLVED)

Yesterday, I started creating a menu and got stuck on an error when trying to send a message to controller.script:

ERROR:GAMEOBJECT: Instance '/controller' could not be found when dispatching message 'show_setting' sent from main:/menu#main-menu

Most likely, I missed something or didn’t read something carefully when creating the menu. For reference, I used the menu_and_game and MainMenu projects.

Here is the controller.script code:

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#menu_proxy", "load")
end

function final(self)
	msg.post(".", "release_input_focus")
end

function on_message(self, message_id, message, sender)
	print(message_id)
	if message_id == hash("proxy_loaded") then
		msg.post(sender, "init")
		msg.post(sender, "enable")
	end 
	
	if message_id == hash("show_game") then
		msg.post("#game_proxy", "load")
		msg.post("#menu_proxy", "final")	
		msg.post("#menu_proxy", "disable")
		msg.post("#menu_proxy", "unload")
	elseif message_id == hash("show_newgame") then
		msg.post("#game_proxy", "load")
		msg.post("#menu_proxy", "final")	
		msg.post("#menu_proxy", "disable")
		msg.post("#menu_proxy", "unload")
	elseif message_id == hash("show_load") then
		msg.post("#load_proxy", "load")
		msg.post("#menu_proxy", "final")	
		msg.post("#menu_proxy", "disable")
		msg.post("#menu_proxy", "unload")
	elseif message_id == hash("show_setting") then
		msg.post("#setting_proxy", "load")
		msg.post("#menu_proxy", "final")	
		msg.post("#menu_proxy", "disable")
		msg.post("#menu_proxy", "unload")
	elseif message_id == hash("show_main-menu_setting") then
		msg.post("#menu_proxy", "load")
		msg.post("#setting_proxy", "final")	
		msg.post("#setting_proxy", "disable")
		msg.post("#setting_proxy", "unload")
	elseif message_id == hash("show_main-menu_load") then
		msg.post("#menu_proxy", "load")
		msg.post("#load_proxy", "final")	
		msg.post("#load_proxy", "disable")
		msg.post("#load_proxy", "unload")
	end
end

Here is the main-menu.gui_script code:

function init(self)
	msg.post(".", "acquire_input_focus")
	sound.play("/music#sound", { gain = 1.0, pan = 0 })

	self.continue_button = gui.get_node("continue_button")
	self.newgame_button = gui.get_node("new-game_button")
	self.load_button = gui.get_node("load_button")
	self.setting_button = gui.get_node("setting_button")
	self.exit_button = gui.get_node("exit_button")
end

function final(self)
	msg.post(".", "release_input_focus")
end

function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed then
		if gui.pick_node(self.continue_button, action.x, action.y) then
			msg.post("/controller#script", "show_game")
		end

		if gui.pick_node(self.newgame_button, action.x, action.y) then
			msg.post("/controller#script", "show_newgame")
		end

		if gui.pick_node(self.load_button, action.x, action.y) then
			msg.post("/controller#script", "show_load")
		end

		if gui.pick_node(self.setting_button, action.x, action.y) then
			msg.post("/controller#script", "show_setting")
		end

		if gui.pick_node(self.exit_button, action.x, action.y) then
			os.exit()
		end
	end
end

Here is the controller.collections structure:

Here is the project file structure:

Just Try Create Game
├───assets
│   ├───font
│   │   ├───sfx
│   │   ├───Capture_it.ttf
│   │   ├───main-menu.font
│   │   ├───ThinFourDownThreeCrazyPink-Regular.ttf
│   │   └───title-game.font
│   ├───images
│   │	└───menu-background.jpg
│   └───music
│		└───main-theme.ogg
├───atlas
│	└───main-menu.atlas
├───collections
│   ├───menu
│   │	├───game.collection
│   │	├───load.collection
│   │	├───main-menu.collection
│   │	└───setting.collection
│   └controller.collection
├───gui
│   ├───load
│   │	├───load.gui
│   │	└───load.gui_script
│   ├───main-menu
│   │	├───main-menu.gui
│   │	└───main-menu.gui_script
│   └───setting
│		├───setting.gui
│		└───setting.gui_script
├───input
│	└───game.input_binding
├───objects
├───scripts
│	└───controller.script
├───tileset
└───game.project

It seems that your controller lives in another world than menu. When you are sending a message to another game world, your address should follow the scheme: worldname:/objectpath#componentname. Your main-menu.gui_script when sending the show_setting message lacks that first part of the address, before the colon. You can read about it in this manual: https://defold.com/manuals/addressing/#urls

Hello, @robotiger77!

Specifying the socket name in the URL did not help. The same error began to appear, along with a reference to a line in the code with a corrected URL, indicating that the syntax was incorrect.

After digging deeper, I found the cause of the error. It turns out that I had duplicate collection names, both collections were called main┏ʕ •ᴥ•ʔ┛

Now there is an error after downloading another collection ( •̀ ᴖ •́ )

I’ll go look for a solution

1 Like