Messages Between Collections (using collection proxies)

As the title says, I am having some difficulty with message passing.

I have used message passing for quite some time now and I believe I have got the hang of it. In every situation that I encountered until now I have been able to use them, so I feel a little stumped by the fact that I cannot see what goes wrong in this instance.

I am using collection proxies, and the relevant parts of the project are (in the hierarchy):

  • Collection A (also with ID as such instead of ‘default’)
    • A factory producing GO’s called ‘a’
  • Collection B (as above)
    • A GO called ‘b’
  • A main collection
    • A loader GO containing proxies for A and B

Now, I load A and B using proxies just fine, and everything works great. At least, it works great until I wish to pass a message from one of the game objects ‘a’ produced by the factory to ‘b’, and to do so I thought the proper syntax would be to set as recipient url as “B:/b”, but this only produces the following error message:

“Could not send message ‘whatever_message_I_have’ from ‘A:/instance1#a’ to ‘B:/b’.”

Strangely, it does not (to me) seem to be the usual error message that is printed when the recipient is not found.

Is the issue somehow related to instances produced by factories? Is there a better (well, anything is better than a non-working way) way for sending messages like the ones I want?

Thank you!

I don’t see any obvious error in what you’ve written. Sending a message to a game object in a collection loaded via a proxy is done “from the outside of the collection” using the absolute URL.

In your case it should be msg.post("B:/b", "mymessage") to post a message from anywhere to a game object with id “b” in collection named “B”. What if you attach a script to game object “b” and in init() do print(msg.url())? This should show the absolute URL to “b”.

I think it’s a poor error message, but it comes from checking that the receiving socket (B:) is valid. Could it be that the event is sent just before the proxy is finished loading?

@britzl doing print(msg.url()) was exactly my first instinct (well, instinct developed when learning messages), and it prints exactlyB:/b, so I am not sure what is going wrong.

@Mathias_Westerdahl mentioned that it might be related to proxy loading, but I am sure it is not. The proxy is soundly loaded before I send the message.

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

I ran into the same issue, but was able to solve it. Make sure whatever you use as B in B:/ is the name of the collection. I had a collection in a main folder, that I was referring to as “main” when it’s name was actually “controller” in the controller.collection object. It’s a silly little thing to miss, but I spent an hour beating my head against the wall by missing it.

2 Likes

Has anyone found a solution to this problem ? I got the same issue. I think its because relevant proxy has not loaded before the message. if we can check this we can find a solution. (message_id == hash(“proxy_loaded”) ). How to check which proxy has loaded?

The sender argument of on_message is the URL to the proxy that was loaded.

@britzl it gives me this. url: [controller:/controller#menuproxy]
i cant compare it with a string. Do i have to split it ?

No, that won’t work. Compare to another URL. Like this:

function on_message(self, message_id, message, sender)
    if message_id == hash("proxy_loaded") and sender == msg.URL("controller:/controller#menu proxy") then
        print("menu has been loaded")
    end
end
1 Like

@britzl thank you . That works. Also thank you very much for your github examples.They are really helpful

2 Likes

I have a similar issue: Could not send message ‘start’ from ‘intro:/intro#intro’ to ‘chapters:/controller#journal’.
image

I want to send a message from intro.gui_script, loaded via collection proxy, to the collection (journal.gui_script ) that has the controller object that loaded it.

Any ideas from your experience? Thanks.

1 Like

Start by putting print(msg.url()) in the init function of the receiving script. This will output the full URL too the script. Does this match the URL you are trying to send the message to?

Yes. Thanks a lot. I did that earlier for another issue, removed it, renamed things… and boom, never crossed my mind to add them again :disappointed_relieved:

2 Likes