how to access object variables in a scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mikbauer

Hi All, New to GoDot.
I have the following seen and I want to change some variables on one of the nodes, but I am not able to do that.
my scene: Control → gridContainer- > button1/2/3
how can I change button color and text property form script attached to the Controller node.

:bust_in_silhouette: Reply From: jgodfrey

To change properties on a given node, you just need a valid reference to that node. For your example, that should be:

$gridContainer/button1.text = "New Text"

That assumes the following (from your above tree reference):

  • The above code is running on the Control node
  • The GridContainer node is named gridContainer
  • The Button in question is named button1
:bust_in_silhouette: Reply From: Rpics

Hi, you can use get_node for example
get_node("Sprite").position
You can use a variable too
var name = get_node("Sprite").position
Then you can use it as you want like
var x = 100 name = x