Switching between collections

Hello, I have organised my game screens in 3 collections: main, lost and win and the corresponding collection proxies: lost_proxy and win_proxy added in game object “collections”" placed in main.collection . I am trying to switch between main.collection and lost.collection. Here is the code:

if (Gamer["floors_achieved"] <= TowerFloors) and (QuestionNumber >= MaxQuestion) then

				msg.post("collections#lost_proxy", "load")
				msg.post("collections#lost_proxy", "enable")
				label.set_text("go#Tower", "You lost 1")

end

but nothing happens. Can you suggest a decision of the problem

You must wait for the collection to load before enabling it.

function init(self)
– Add initialization code here
– Learn more: https://defold.com/manuals/script/
– Remove this function if not needed

end

function final(self)
– Add finalization code here
– Learn more: https://defold.com/manuals/script/
– Remove this function if not needed
end

function update(self, dt)
– Add update code here
– Learn more: https://defold.com/manuals/script/
– Remove this function if not needed
end

function on_message(self, message_id, message, sender)
– Add message-handling code here
– Learn more: https://defold.com/manuals/message-passing/
– Remove this function if not needed
if messade_id == “WIN” then
label.set_text(“go#Tower”, “You win message”)
counter = 0
msg.post(“collections#win_proxy”, “load”)

	print ("You win 2")
end

if message_id == hash("proxy_loaded") and counter<2 then
		-- New world is loaded. Init and enable it.
		counter = counter + 1
		msg.post("collections#lost_proxy", "enable")
		label.set_text("go#Tower", "You lost 1")
end	

end

function on_input(self, action_id, action)
– Add input-handling code here. The game object this script is attached to
– must have acquired input focus:

– msg.post(".", “acquire_input_focus”)

– All mapped input bindings will be received. Mouse and touch input will
– be received regardless of where on the screen it happened.
– Learn more: https://defold.com/manuals/input/
– Remove this function if not needed
end

function on_reload(self)

end

Hi @Maria_Berova, and welcome!

To make the code posts more readable, put three “```” around your code block, in order to format it (i.e. markdown format):

```
local v = 17
```

becomes:

local v = 17

There’s also a typo in the code: “messade_id”.

3 Likes