Question about loading proxy

Hi! Why I can’t send message to controller, which loads proxies?

ERROR:SCRIPT: /game/scr/player.script:143: Could not send message 'unload_level' from 'level1:/player#player' to 'main:/loader#controller'.
stack traceback:
	[C]: in function 'post'
	/game/scr/player.script:143: in function </game/scr/player.script:141>

The message sends the object to the player in the collection level:

msg.post("main:/loader#controller", "unload_level")

And here controller code:

function on_message(self, message_id, message, sender)
	if message_id == hash("proxy_loaded") then
		msg.post(sender, "init")
		msg.post(sender, "enable")
		msg.post(sender, "acquire_input_focus")
	elseif message_id == hash("unload_level") then
		local proxy = msg.url(self.current_proxy)
		msg.post(proxy, "disable")
		msg.post(proxy, "final")
		msg.post(proxy, "unload")
		self.unloader = sender
		msg.post(self.current_proxy, "load")
	end
end

I am pretty sure you are not sending that message to the right place. Unload messages need to be sent to a collectionproxy, and you are sending it to a script. Look here:

ERROR:SCRIPT: /game/scr/player.script:143: Could not send message 'unload_level' from 'level1:/player#player' to 'main:/loader#controller'.
stack traceback:

it says you’re sending the message to “main:/loader#controller” which is a script. Try sending it to “main:/level/level1”.

But i want to send message from player, wich die to controller, to make proxy reload. Anyway, i’m trying to send message to “main:/level#level1”. It’s the same error.

Well, as @88.josh writes, you need to post the “unload” message to the collection proxy if it is supposed to unload. What you typically do is to have a controller script somewhere that orchestrates the loading and unloading of collection proxies based on state and all messages to load and unload go via that controller script. You can take a look at the recently added color-slide tutorial for an example: https://github.com/defold/tutorial-colorslide or this example with a menu and a “game” that is loaded/unloaded via a controller: https://github.com/britzl/publicexamples/tree/master/examples/menu_and_game

1 Like