Could not send message 'casual_game' from 'loader:/go#loader' to 'main:/factories#startgame' (solved)

Can someone help me know why this isn’t working?

I have a loader (aka controller) that loads my main collection when the user selects the play button. I’m Trying to also send a message to the main telling the main collection what mode to play. I guess I can create 3 different collection of game modes, but it’s so much smaller code if I just capture the few minor differences in the main collection. So anyway I get this error:

Could not send message ‘casual_game’ from ‘loader:/go#loader’ to ‘main:/factories#startgame’.

I’ve done a print(msg.url()) and confirmed it’s the correct full URL from the loader to the startgame script.

this is my loader script:

local function load_menu(self)
	msg.post("go#mainmenu", "load")
	msg.post("go#mainmenu", "enable")
end

local function unload_menu(self)
	msg.post("go#mainmenu","unload")
end

local function load_main(self)
	msg.post("go#main", "load")
	msg.post("go#main", "enable")
	msg.post("main:/factories#startgame", hash("casual_game"))
end

local function unload_main(self)
	msg.post("go#main", "unload")
end

function init(self)
	msg.post(".", "acquire_input_focus")
	load_menu(self)
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start_casual") then
		unload_menu(self)
		load_main(self)
	elseif message_id == hash("goto_menu") then
		unload_main(self)
		load_menu(self)
	end
end

Any suggestions are very much welcomed.

Already solved it. I had to wait for the proxy to load the collection.

if message_id == hash("proxy_loaded") then
		if game_mode == "casual" then
			msg.post("main:/factories#startgame", hash("casual_game"))
		end
	end

Collection proxy manual (defold.com)

1 Like

Good that you solved it.

Also, please assign a category for your posts :slight_smile:

Which category does this fit best in when inintially posted? I’m new here and not sure which one is best for this type of question.

Thank you.

Usually the Question category is the best, unless you know for sure that it is a bug in which case the Bugs category is best.

1 Like