How set_position for game object with proxy loader

Hey there,

Is possible send a message from loader.script to an object that is inside a proxy?

Folder structure

Principal collection

Level1Collection

The idea is send a message from loader script to player object that belongs to Level1Collection, I need update the object position dynamically.

Thanks in advance.

Yes, that’s possible. If you select the root of your collection you see its name. If the name is “level1” then the URL to hero would be “level1:/hero”.

Thanks @britzl, I have tried a lot of urls without luck, when I add the url level1:/hero the next error appears on console.

This is the level1 collection

msg.post("level1:/hero", "update_position", {pos = vmath.vector3(message.heroX, message.heroY, message.heroZ)})

I need more context.

  • You have a collection named loader.collection. This is the bootstrap collection in game.project
  • The loaded collection contains a collection proxy to level1.collection
  • Level1 collection is named level1
  • Inside level1.collection there is a game object with id hero
  • Inside loader.collection there is a script that posts a message to hero

Is all of the above correct? Is level1.collection loaded and enabled before the message is sent? What if you have a script on hero that does: print(msg.url()) in its init() function?

All points are correct @britzl .

I can access to loader:/loader#level1proxy without problem, but I can’t send messages to level1:/hero, for example.

This is the content of level1proxy

And this is the code in main/loader.script on loader (principal collection).

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#level1proxy", "load")
	
	self.worlds = {
		[hash("#level1")] = "#level1proxy",
		[hash("#level2")] = "#level2proxy",
	}
end

function on_message(self, message_id, message, sender)
    if message_id == hash("end_level") then
        local proxy = msg.url("#proxy")
        msg.post(proxy, "disable")
        msg.post(proxy, "final")
        msg.post(proxy, "unload")
        self.unloader = sender
    elseif message_id == hash("proxy_unloaded") then
        msg.post(self.unloader, "level_ended")
    elseif message_id == hash("proxy_loaded") then
		msg.post(sender, "init")
        msg.post(sender, "enable")
        print(sender)

        local current_world = nil
        local new_world = nil
        current_world = self.worlds[message.current_world]
        new_world = self.worlds[message.new_world]

        if new_world then
        	msg.post(current_world, "disable")
        	msg.post(current_world, "final")
        	msg.post(current_world, "unload")
        	msg.post(new_world, "load")

        	if message.heroX ~= 0 and message.heroY ~= 0 then
        		msg.post("level1:/hero", "update_position", {pos = vmath.vector3(message.heroX, message.heroY, 1)})
        	end
        end       
	end
end

Thanks for your support.

Could you please add a print() in the init function of hero and one immediately before posting the message? Do you see the hero init print first?

Feel free to share the project with me (bjorn.ritzl@king.com) and I can take a look.

Hi @britzl, I shared the project with you from my dashboard, the project name is RPG.

About adding a print in my hero init function, all works fine, except the call from the loader.

The issue appears when the hero go to the next level using the stairs.

Thanks in advance.

Ok, so it looks like you’re not loading and unloading properly. I’ll get in touch on Slack.