How to get game object properties in a gui script

Hey guys, I’m having trouble with some GUI stuff currently I have a text node that has a text value of 0 but I want it to display the property health of my player object but for the life of me, I cant figure of out why I just get the error
bad argument #4 to ‘get’ (GOScriptInstance expected, got userdata)

function update(self, dt) local health = go.get("main:/Player/controller#script", "health") gui.set_text(playerHealth, 1000) end
1 Like

“argument #4” is an implicit argument that’s used in game object scripts to work properly with go.get(). From a GUI script, you won’t be able to directly use go.get(); I suggest using message passing or global variables to share information between your player and the GUI script.

2 Likes

Preferably message passing… :slight_smile:

1 Like

yea Im working on using messages

how does one send a message to a gui script?

Send the message to the gui component.

See http://www.defold.com/manuals/message-passing/ for some examples.

Thank you il try that when I get home

Every component (be it a sprite, script, gui_script or anything else) you add to a game object will get it’s own unique URL that can be used to pass messages to the component using msg.post(). The manual on message passing should describe this in detail. but if there is anything that is unclear then please ask here and we’ll try to explain.