[SOLVED] Error when messaging collection proxied GUI address

Hello. I’ve followed the ColorSlide tutorial through to the end and everything works as expected.

I’m now trying to implement the first ‘what next?’ suggestion (updating LEVEL display) by posting the level number from loader.script to collection-proxied level.gui_script, but get an error:

ERROR:SCRIPT: main/loader.script:33: Could not send message ‘level_indicator’ from ‘default:/loader#loader’ to ‘level_1:/level_1#gui’.
stack traceback:
[C]: -1: in function post
main/loader.script:33: in function <main/loader.script:27>

DEBUG:SCRIPT: url: [level_1:/level_1#gui]

loader.script

-- << are the lines I've added
function on_message(self, message_id, message, sender)							-- line 27
	if message_id == hash("load_level") then
		self.current_level = message.level
		local proxy = "#proxy_level_" .. self.current_level
		local proxygui = "level_1:/level_1#gui"			-- << simplified to a string for testing <<
		msg.post(proxy, "load")
		msg.post(proxygui, "level_indicator", { level = self.current_level } )		-- << line 33 <<
	elseif message_id == hash("next_level") then
		...

level.gui_script

function on_message(self, message_id, message, sender)
	print(msg.url())															-- <<
	if message_id == hash("level_completed") then
		local done = gui.get_node("done")
		gui.animate(done, "position.x", 320, gui.EASING_OUTSINE, 1, 1.5)
	elseif message_id == hash("level_indicator") then						-- <<
		local indicator = gui.get_node("level")								-- <<
		print("here")															-- <<
		gui.set_text(indicator, message.level)									-- <<
	end
end

collection structures:



The DEBUG:SCRIPT: url: [level_1:/level_1#gui] after the error is down to level.script (successfully) messaging the same gui_script at a later, unrelated time:

level.script

				--check whether the board is solved
				if all_correct(self.bricks) then
					msg.post("#gui", "level_completed")
					self.completed = true
				end

I know there are other ways of updating the LEVEL display, but I’d be better getting to grips with the messaging system. “level_1:/level_1#gui” (socket:/path#fragment) seems like it should be right.

Someone else with a similar unresolved problem:

Thanks

My first thought is you should wait for the “proxy_loaded” message and enable it before sending messages to it

Thanks @Chung_Xa , that was exactly it - I thought it might be a timing issue but wasn’t entirely sure.

This worked:

function on_message(self, message_id, message, sender)
	if message_id == hash("load_level") then
		...
	elseif message_id == hash("next_level") then
		...
	elseif message_id == hash("unload_level") then
		...
	elseif message_id == hash("proxy_loaded") then
		msg.post(sender, "init")
		msg.post(sender, "enable")
		local proxygui = "level_1:/level_1#gui"								-- <<
		msg.post(proxygui, "level_indicator", { level = self.current_level } )	-- <<
	end
3 Likes