The proxy example is functional, but maybe a little confusing at first. This is my own loader script I made which handles all collection proxy loading/unloading.
-------------
-- Helpers --
-------------
local show_proxy
function show_proxy(self, proxy)
-- If a proxy is loaded already, unload it
if self.current_proxy then
msg.post(self.current_proxy, "unload")
end
-- Load the requested proxy
msg.post(proxy, "async_load")
end
-----------------
-- End Helpers --
-----------------
----------------------
-- Defold functions --
----------------------
function init(self)
msg.post(".", "acquire_input_focus")
-- Load the first proxy of the game. Usually a main menu or loading splash screen
show_proxy(self, "#first_proxy_you_want_player_to_see_when_starting_the_game")
end
function on_message(self, message_id, message, sender)
-- When you send a message to load a proxy, it will send a message back to you once it is successfully loaded with the message_id of hash("proxy_loaded")
-- You can go ahead and set the self.current_proxy to track the newly loaded proxy, and enable it, running the init() of all of the game objects, gui objects, etc.
if message_id == hash("proxy_loaded") then
self.current_proxy = sender
msg.post(sender, "enable")
elseif message_id == hash("switch_proxy") then
show_proxy(self, message.switch_to)
end
end
--------------------------
-- End Defold functions --
--------------------------
Then your main.collection
can look like this
Switching to a proxy is then done like so
msg.post("main:/loader#loader", "switch_proxy", { switch_to = "#world_proxy" })