End screen Help

im making a screen at the end appear when the characters health is equal to zero.

local function player_damage(self)
	if self.player_health > 0 then 
		self.player_health = self.player_health - damage
		print(self.player_health)
	elseif self.player_health == 0 then
	load_endscreen(self)
	end
end

and load_endscreen is in my loader script and a global variable

function load_endscreen(self)
	msg.post("go#endscreen", "load")
	msg.post("go#endscreen", "enable")
end

but i keep getting an error saying

and i have no idea whats causing it

The error tells you that there is no game object with the id ā€œgoā€ at the same level in the scene graph as the script which is sending the message. What does your collection look like?

If the ā€œgoā€ object is at the root then it should be ā€œ/goā€

Also note that the collection wonā€™t be loaded until later, so itā€™s no good to send the ā€œenableā€ event at the same time as the load event.

Example of loading a collection proxy here: Proxy

If itā€™s an option, I can heartily recommend Monarch, a screen manager that deals with all the loading/unloading of screens for you.

what do you mean collection

This is my loader collection

image

Ok, and the msg.post("go#endscreen", "load") was sent from where? From the loader.script?

yeah

No I donā€™t think so. Looking at your screenshot it looks like you are sending msg.post("go#endscreen", "load") from main:/hero#heromove.

If it is indeed the heromove.script that sends the message then my recommendation is that you restructure your logic a bit. The heromove.script can send a message to the loader.script (using the full path) and then the loader script takes care of calling ā€œloadā€, ā€œenableā€ etc

1 Like

Is that correct?
The error message says itā€™s sent from main:/hero#heromove ?

i have a the code so that when the player dies it does the function

local function player_damage(self)
	if self.player_health > 0 then 
		self.player_health = self.player_health - damage
		print(self.player_health)
	elseif self.player_health == 0 then
		load_endscreen(self)
		enable_endscreen(self)
	end
local function load_endscreen(self)
	msg.post("go#endscreen", "load")
end

local function enable_endscreen(self)
	msg.post("go#endscreen", "enable")
end

But this will post a message to a game object with id ā€œgoā€ in the same collection as the hero? And it doesnā€™t look like that is the case. Your loader is in another collection so you must specify the collection id as well:

msg.post("foo:/go#loader", "load")

Replace ā€œfooā€ with the id of the loader collection (select the collection root to see the id/name).

1 Like

now its saying
Could not send message ā€˜loadā€™ from ā€˜main:/hero#heromoveā€™ to ā€˜go:/go#loaderā€™.
stack traceback:

Is the name of the collection containing the loader really ā€œgoā€?

nevermind i got it to work i dont know if its the most efficent

	elseif self.player_health == 0 then
		msg.post("loader:/go#endscreen", "load")
		msg.post("loader:/go#endscreen", "enable")
	end

When the screen appears do you know how to make everything else to stop like enemy movement and have a moving floor so how would i make that stop moving

i could disable the main collection but i would prefer if it still showed the gameplay

You can set the timestep of your game to 0. This will pause all updates, or rather, the delta time will always be 0.