Loader script not initianlizing

I’ve tried for a few days now to figure this out on my own to no avail. I’ve read, and reread, the chapter on Collection Proxies and scoured the forum for an answer but I could not find one. I think I’ve got a handle on collection proxies (for the most part), but I seem to be stuck on this. The main menu, level 1 and game over (when player dies ) screen all load correctly, and from the game over screen i can restart the level. When I try to go from the game over screen to the main menu, however, I get a blank screen. It seems like the game over gui unloads correctly, however the loader script (see below) does not initialize. I had it print to be sure the unload happened and it does. I do not get an error, just a blank screen. How to I get the loader script to restart to come back to the main menu? I’m not sure what I’m doing wrong and any help would be appreciated.

Here’s my setup:

main.collection
 >loader [go]
      >gameOver_proxy [contains game over gui and gui script]
      >level01_proxy [contains level, enemies, player, scripts, etc.]
      >loader.script
      >mainMenu_proxy [contains main menu gui and gui script]

Loader script:

function init(self)
	msg.post("#mainMenu_proxy", "load")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("proxy_loaded") then
		msg.post(sender, "init")
		msg.post(sender, "enable")
		msg.post(sender, "acquire_input_focus")

		self.current_proxy = sender
		
	elseif message_id == hash("start_level01") then
		msg.post(sender, "disable")
		msg.post(sender, "unload")
		msg.post("#level01_proxy", "load")

	elseif message_id == hash("game_over") then
		msg.post("#gameOver_proxy", "load")
		msg.post(self.current_proxy, "disable")
		
	elseif message_id == hash("unload_menu") then
		msg.post("main:/loader#mainMenu_proxy", "unload")

	elseif message_id == hash("unload_gameOver") then
		msg.post("main:/loader#gameOver_proxy", "unload")
	end
end

gameOver.gui script:

function init(self)
	msg.post(".", "acquire_input_focus")

	self.restartLevel = gui.get_node("restart")
	self.mainMenu = gui.get_node("main_menu")
	msg.post("main:/loader#level01_proxy", "unload")
end

function final(self)
	msg.post(".", "release_input_focus")
end

function on_input(self, action_id, action)
	if action.pressed and gui.pick_node(gui.get_node("restart"), action.x, action.y) then
		sound.play("#sound")
		gui.play_flipbook(self.restartLevel, hash("button_selected"))
		msg.post("main:/loader#loader", "start_level01")
		msg.post("main:/loader#loader", "unload_gameOver")
	elseif action.pressed and gui.pick_node(gui.get_node("main_menu"), action.x, action.y) then
		sound.play("#sound")
		gui.play_flipbook(self.mainMenu, hash("button_selected"))
		msg.post("main:/loader#loader", "init") -- if I replace with "main:/loader#mainMenu_proxy", "load" I still get a blank screen with no errors.
		msg.post("main:/loader#loader", "unload_gameOver")
	end
end

hello @artschoolcamouflage as I see in your code in loader handle script you dont mention the mainmenuproxy so how to load a proxy where is not mention to load with msg? except if i didnt see well your code . thanks

should have one in loader script

 elseif message_id = hash("mainmenuproxy") then
      msg.post( "#mainmenuproxy", "load") 
 end

so to make load but in loader script there is not
so cannot load it, i hope this to be a solution
thanks

One more thing in your loader script I do not see the unload msg to do the disable somewhere by taking the message, you write only about load. I hope this helps you find the solution. thanks

Yep, that worked. Thanks for pointing that out.

I’ve got some confusion though: The init(self) function of the loader script loads the mainMenu_proxy, which works when the game launches, so why doesn’t that work when coming back to it from a script? Shouldn’t loader.script initialize again when sent the message to “init”?

The unload message is in the level controller script that gets sent upon loading of level 1, so that’s why it’s not in the two scripts above.

1 Like

It will be better load , unload have in one script that handle that, and also I think in init does not receive a message as init is to initialize the loader script. So loader comes again when a msg call to it from the other script and receive it with a message_id. init is function of loader and not of gameover to see it. thanks

What do you mean by this? Isn’t the loader.script loaded once on application startup (since it is part of the bootstrap collection). The init function will only be called once on application startup if this is the case.

1 Like

Yes, the init function of the loader script loads upon start up. I was thinking it could be called again because it’s a script, but now I’m realizing that loader.script never stops running since it’s the central script controlling the loading and unloading of proxies. That would mean it cannot go through init again. Hey, I think I learned something! Thanks @Elpidoforos_Gkikas and @britzl !

2 Likes