Msg.post(proxy, "unload") doesn't working (SOLVED)

Hello guys…

This is the life cicle of my game “menu” > “selectPlayer” > “world1” > “menu”

but when I am try to access the “menu” from “world1” i receive this message:

ERROR:GAMESYS: The collection /loader/menu.collectionc could not be loaded since it was already. Message 'load' sent from loader:/go#script to loader:/go#menu.

Here is my loader collection:

function init(self)
   self.lastSender = nil
   msg.post(".", "acquire_input_focus")
   msg.post("#", "menu")
   
   
end

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

function update(self, dt)
    
end

function on_message(self, message_id, message, sender)
   
   if message_id == hash("menu") then
  	 self.lastSender = sender
  	 msg.post("#menu", "load")
   end
  
  
   if message_id == hash("selectPlayer") then
  	  self.lastSender = sender
  	 msg.post("#selectPlayer", "load")
   end
   
    if message_id == hash("world1") then
  	 self.lastSender = sender
  	 msg.post("#world1", "load")
   end
  
  
  if message_id == hash("gameover") then
  	 msg.post("#winLose", "load")
  	  self.lastSender = sender
  	 --pprint("novo sender" .. sender)
  	-- print("recebeu loader")
  	 
  end
  if message_id == hash("proxy_loaded") then
                -- New world is loaded. Init and enable it.
              msg.post(sender, "init")
              msg.post(sender, "enable")
                   
              if self.lastSender ~= nil then
              --pprint("unloadding" .. sender)
	              local proxy = msg.url(self.lastSender)
	    		  msg.post(proxy, "disable")
	   			  msg.post(proxy, "final")
	   			  msg.post(proxy, "unload")
	   		  end
                
     end
end

function on_input(self, action_id, action)
    -- Add input-handling code here
    -- Remove this function if not needed
end

function on_reload(self)
    -- Add reload-handling code here
    -- Remove this function if not needed
end

What it is wrong here?

If I called msg.post(proxy, “unload”) why am I receiving this message?

It seems like the “menu” isn’t properly unloaded. Could you perhaps add a check for when you receive “proxy_unloaded” and print the sender and make sure that the menu is unloaded? In general it’s good to add a couple of print() statements in this kind of situation and print things such as self.lastSender and the different messages you receive.

Hey @britzl here is the prints…

INFO:ENGINE: Defold Engine 1.2.96 (0060183)
INFO:ENGINE: Loading data from: http://192.168.1.100:8080/build/default
INFO:ENGINE: Initialised sound device 'default'

DEBUG:SCRIPT: calling: [loader:/go#script]
DEBUG:SCRIPT: init and enable: [loader:/go#menu]
DEBUG:SCRIPT: disable, final and unloading: [loader:/go#script]
DEBUG:SCRIPT: calling: [menu:/go#gui]
DEBUG:SCRIPT: init and enable: [loader:/go#selectPlayer]
DEBUG:SCRIPT: disable, final and unloading: [menu:/go#gui]
DEBUG:SCRIPT: calling: [selectPlayer:/go#gui]
DEBUG:SCRIPT: init and enable: [loader:/go#world1]
DEBUG:SCRIPT: disable, final and unloading: [selectPlayer:/go#gui]
DEBUG:SCRIPT: calling: [main:/hpLife#gui]
ERROR:GAMESYS: The collection /loader/menu.collectionc could not be loaded since it was already. Message 'load' sent from loader:/go#script to loader:/go#menu.
INFO:DLIB: Flushing http cache to disk
INFO:DLIB: SSDP: Done on address 192.168.1.100

Here is the loader script with prints

function init(self)
   self.lastSender = nil
   msg.post(".", "acquire_input_focus")
   msg.post("#", "menu")
   
   
end

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

function update(self, dt)
    
end
local function goto(self,sender,destination)
 	self.lastSender = sender
 	print("calling: " .. sender)
  	msg.post(destination, "load")
end
function on_message(self, message_id, message, sender)
   
   if message_id == hash("menu") then
  		goto(self,sender,"#menu")
  	
   end
  
  
   if message_id == hash("selectPlayer") then
   	 goto(self,sender,"#selectPlayer")
   end
   
   if message_id == hash("world1") then
  	 goto(self,sender,"#world1")
   end
  
  
  if message_id == hash("gameover") then
   goto(self,sender,"#winLose")
  end
  
  if message_id == hash("proxy_loaded") then
                -- New world is loaded. Init and enable it.
              msg.post(sender, "init")
              msg.post(sender, "enable")
              print("init and enable: " .. sender)
                   
              if self.lastSender ~= nil then
              --pprint("unloadding" .. sender)
	              local proxy = msg.url(self.lastSender)
	              print("disable, final and unloading: " .. proxy)
	    		  msg.post(proxy, "disable")
	   			  msg.post(proxy, "final")
	   			  msg.post(proxy, "unload")
	   		  end
                
     end
end

function on_input(self, action_id, action)
    -- Add input-handling code here
    -- Remove this function if not needed
end

function on_reload(self)
    -- Add reload-handling code here
    -- Remove this function if not needed
end

As i said before i’m really unloading the menu scene

DEBUG:SCRIPT: disable, final and unloading: [menu:/go#gui]

Have you any idea?

But it seems as though you are not unloading the collection proxy?

DEBUG:SCRIPT: disable, final and unloading: [loader:/go#script]

It looks like you are doing msg.post() with disable, final and unload to a script component (go#script) when you in fact must post those three messages to the collection proxy.

You should also add a check for proxy_unloaded just to be 100% sure that the proxy is indeed unloaded. Like this:

if message_id == hash("proxy_loaded") then
    ... load stuff here
elseif message_id == hash("proxy_unloaded") then
    print("unloaded", sender)
end
2 Likes

yeah you are right. there is no answer to message “proxy_unloaded”.

I have changed self.lastSender to a self.breadCumb and now it’s working.

local function goto(self,sender,destination,message)
 	--print(sender, " calling for: " , destination)
 	
 	table.insert(self.breadCumb,destination)
 	if message == nil then message = {} end
  	msg.post(destination, "load",message)
end
function on_message(self, message_id, message, sender)
   
   if message_id == hash("menu") then
  		goto(self,sender,"#menu")
  	
   end
  
  
   if message_id == hash("selectPlayer") then
   
   	 goto(self,sender,"#selectPlayer")
   end
   
   if message_id == hash("world1") then
  	 goto(self,sender,"#world1")
   end
   
   if message_id == hash("credits") then
  	 goto(self,sender,"#credits")
   end
  
  
  if message_id == hash("gameover") then
   	goto(self,sender,"#winLose",message)
  end
  
  if message_id == hash("win") then
   	goto(self,sender,"#win",message)
  end
  
  if message_id == hash("proxy_loaded") then
                -- New world is loaded. Init and enable it.
              msg.post(sender, "init")
              msg.post(sender, "enable")
              
                  
             -- print("init and enable: " .. sender)
             
                   
              if #self.breadCumb > 1 then
              --pprint("unloadding" .. sender)
	              local proxy = msg.url(self.breadCumb[#self.breadCumb - 1])
	             -- print("disable, final and unloading: " .. proxy)
	    		  msg.post(proxy, "disable")
	   			  msg.post(proxy, "final")
	   			  msg.post(proxy, "unload")
	   		  end
	
    end
end

Thanks!

1 Like