Problem with passing message from the loader script to a gui (SOLVED)

In the game i’m making ive got a timer set that is used to time how long it takes for the player the complete the level, i would then like the time to be displayed on a gui that says level complete with the time.

So i have coded my game to: send the time (self.timer) to the loader script which will then display the gui with the time.

So below is the code that sends the time to the loader script:

msg.post("loader:/go#loader", "game_complete", {timer = self.timer})

This is the code in the loader that sends the time to the gui and gets the gui to run:

	if message_id == hash("game_complete") then
		unload_game(self)
		self.timer = message[timer]
		load_level_complete(self)

local function load_level_complete(self)
	msg.post("/level_complete#level_complete", "timer", {timer = self.timer})
	msg.post("go#level_complete", "load")
	msg.post("go#level_complete", "enable")
end
	end

I’ve got 2 errors:

the first is caused when i assign self.timer = 0 in the init function of the loader. I’m not sure why it does this nor how i should fix it. (Do i even need to assign self.timer in the init function?)

the second is caused by an improper url when i want to send the time to the gui from the loader. I didn’t see any problem with the URL so i’m not sure what is causing it?

Looks like we’re missing some code. Can you also highlight which line is line 41?

function init(Self)
	msg.post(".", "acquire_input_focus")
	load_menu(self)
	self.timer = 0
end

line 41 is where the 1st error is coming from as this is where self.timer is initiated

Self shouldn’t be capitalised here!

2 Likes

cheers thats stopped the first error but for some reason it cant find the level complete gui, thanks very much

Put this in the target script to find the URL:

print(msg.url())

I note you mention “folder”, remember the file structure is not what matters for URLs.

ims till using the function below to send the message:

local function load_level_complete(self)
	msg.post("go#level_complete", "load")
	msg.post("go#level_complete", "enable")
	msg.post("level_complete:/level_complete#level_complete", "timer", {timer = self.timer})
end

When i got it to print the URL it gave me:
image

Which is the same as the 1 in the function but i’m now getting the error:

Is go#level_complete the collection proxy for level_complete? In that case you probably need to wait for the proxy to actually be enabled. This means you can’t send the “timer” message in the same frame as you send load and enable.

1 Like

do you know how i could program it to send the message only after it has loaded?

Use a timer with delay 0. Check the API reference and timer examples on the website to learn how to use it.