Passing parameters when load collection proxy

#1

hi ,
I am using collection proxy to switch between two collections,

local function loadGame(self)
	msg.post("/game#gameProxy", "load")
	msg.post("/game#gameProxy", "enable")
	msg.post("oombi_game:/game_body#oombi1", "user_need_to_create_private_room")
end

local function unloadGame()
	msg.post("/game#gameProxy", "unload")
end

local function loadLogin(self)
	msg.post("/game#loginProxy", "load")
	msg.post("/game#loginProxy", "enable")
end

local function unloadLogin(self)
	msg.post("/game#loginProxy", "unload")
end

i need to pass game type “Manual” or auto as a parameter when load game (“loadGame”) function,
but when i use "msg.post(“oombi_game:/game_body#oombi1”, “user_need_to_create_private_room”) " it gives "Could not send message ‘user_need_to_create_private_room’ from ‘main:/game#main’ to ‘oombi_game:/game_body#oombi1’

are there any way to do this process

58%20AM

14%20AM

29%20AM

0 Likes

#2

The engine will send a message back to your script when the proxy is loaded, then you can send your message:

...

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("oombi_game:/game_body#oombi1", "user_need_to_create_private_room")
    end
end

See https://www.defold.com/manuals/collection-proxy/#_loading_a_collection

3 Likes

#3

Is there any new way since this post to pass parameters to collection proxy?
This is quite painful to pass a message once the collection is loaded. A simple message passing when collection is initialized would be very much appreciated.

0 Likes

#4

Nope. You need to send the message manually. Or build something using Lua modules.

In the Monarch screen manager you can do something like:

-- show the game screen and pass some data to it
-- this will load the collection from a proxy
-- or spawn from a collection factory
monarch.show("game", nil, { foo = "bar" })

-------------------------------

-- read the data from a script in the loaded game screen
function init(self)
    local data = monarch.data("game")
    print(data.foo) -- "bar"
end
0 Likes