Error sending messages between proxies

Hello, I am trying to get it so when I select a difficulty on my difficulty select screen, the difficulty selected is passed into the level collection to the enemies so that I can give them different properties accordingly. I’ve tried a few things to try and fix this but I ultimately keep getting this same error.

I assume this is because in some cases I have tried it is trying to send the message before the new proxy is loaded?

I have this to load the proxies and also pass the difficulty

function on_input(self, action_id, action)
	if action.pressed and gui.pick_node(gui.get_node("easy"), action.x, action.y) then
		self.diff = "easy"
		msg.post("main:/controller", "show level",{difficulty = self.diff} )

		--timer.delay(0.5, false, easy_msg())
		--(insert code here for easy difficulty message)
	elseif action.pressed and gui.pick_node(gui.get_node("medium"), action.x, action.y) then
		self.diff = "medium"
		msg.post("main:/controller", "show level",{difficulty = self.diff} )
		--(insert code here for easy difficulty message)
	elseif action.pressed and gui.pick_node(gui.get_node("hard"), action.x, action.y) then
		self.diff = "hard"
		msg.post("main:/controller", "show level",{difficulty = self.diff} )
		--(insert code here for easy difficulty message)
	elseif action.pressed and gui.pick_node(gui.get_node("back"), action.x, action.y) then
		msg.post("main:/controller", "show title screen")
	end
end

And then I try to do this and this is where the error is coming from

elseif message_id == hash("show level") then
		-- level 
		msg.post(self.current_collection, "unload")
		msg.post("#level_proxy", "load")
		msg.post("#", "load")
		self.current_collection = "#level_proxy"
		self.diff = message.difficulty
		msg.post("level:/enemies", "difficulty", {difficulty = self.diff})

Not entirely sure how to get around this.

Not sure why half of my code has sent as text apologies for that.

I believe I have fixed this. I used a boolean variable to check if it was the level proxy being loaded when it received a proxy_loaded message and now this seems to work.

1 Like

Exactly. You need to wait for the proxy loaded message before you can do anything with the loaded collection.

I fixed it for you. You should surround your block of code with three `

    ```
    your code
    ```
3 Likes