Relative URL struggles between collections

I’m missing something fundamental about addressing & collections. I’ve read through the API docs for game objects and the API docs for message, as well as the “Addressing in defold” doc several times. However, I can’t figure out, given a platform_pinwheel.collection structure like this:

…how to address the “pinwheel” game object from the various “floating_platform” game objects:

I’ve tried “pinwheel”, “/pinwheel”, “../pinwheel”, plus various combinations of constructing URLs programmatically, but the only thing that works is hardcoding the URL of a single instance of “pinwheel.” Which of course defeats the purpose of having a platform_pinwheel.collection that I can place in several locations, via the editor, in a single level.

This is something that seems like it should be easy (and with other relative addressing schemes: URLs, file paths, etc, it would be easy), so since it’s not working the way I expect, I imagine there’s something I’m misunderstanding here…

Hm, based on Message passing and addressing - #5 by ross.grams it may be that what I’m trying to do (relatively address a sibling collection) is not possible.

I think it would be powerful to be able to enter “../pinwheel” - and would also map to how Internet URLs actually work, where “..” walks up a path segment. Curious why that’s not supported in defold’s url system.

Reversing the direction of communication worked, but it turned a simple declarative connection (“../pinwheel”) into imperative “hook things up” code in init and added some checks in the platforms (“has this been hooked up yet?”).

I’m open to play around with your problem, but please provide the source code of your project. I’m still a beginner, but I can try to solve your issue.

Add this to the script attached to GO pinwheel:

local my_url = msg.url()
print(my_url) --> url: [current_collection:/my_instance#my_component]

You need the absolute URL to address across collections (including the collection name).

1 Like