How to post a message to a game object in a loaded collection? (SOLVED)

Im not sure how to approach this problem that I have.

I have a Gamescreen Collection that houses a levels game object and a UI game object. The levels object contain proxies(which contains Level collections, level1, level2, etc) and a proxy manager script. Each level collection has an instance of the player character.

The issue is that my UI contains the onscreen buttons to move the character for mobile. So far I’ve been using my keyboard to control the player directly from its script. How exactly do I construct an address that involves going into loaded proxies. i.e to reach the player character. To pass messages such as move left, move right, jump, etc? Is there a better way to approach this? I’m thinking I could record the bounds of the buttons in the player script but it sounds tedious. Any ideas?

msg.post("id_of_collection:/id_of_player", "my_message")

Another approach would be to put the on-screen controls in each level (hosted in a shared game object/gui component obviously).

2 Likes

Clarification: it’s not the id of the proxy component but id of the collection loaded by the proxy component. You set the id in the collection file.

1 Like

Yes, my bad. I’ve updated my answer.

In that case would that make it

msg.post("level"..level_id..":/player", "move_left")
--OR
--Gamescreen has the UI the message is sent from
--levels is the game object that contains the proxies 
--level..level_id is the current loaded level(proxy). level_id being 1-N
msg.post("Gamescreen:/levels/level"..level_id.."/player", "move_left")

?

This!

1 Like

Pro tip: Put print(msg.url()) in the init() function of you player script to see the url.

3 Likes

Ill try it out Thanks alot