Accessing go.property with go.get [SOLVED]

Can I access a named go.property with go.get from another go?

I get the error does not have any property called 'val' even though ‘val’ is declared as a go.property in my go.

You need to specify the script component in the url and not only the game object (the property is on the script, not the game object):

-- does not have any property called 'val'
local val = go.get("some_go", "val")

-- assuming your script component has id ''script_id'
local val = go.get("some_go#script_id", "val")

Okay, thanks that makes sense. Is it possible to append “#script” to a hashed url somehow?

Use the third form of msg.url: ’ msg.url([socket],[path],[fragment])

So if you have a hash ID, then:

msg.url(nil, my_id, "script") -- Do NOT include the '#'.

Or if you have a URL, then:

msg.url(nil, my_url.path, "script")

Of course you can include ‘my_url.socket’ if you actually have it and need it.

2 Likes

Perfect. That works exactly as I need, thanks!

2 Likes