In GDScript, you can access variables in other scripts if they are attached to nodes by getting the node, and then directly accessing the variable. For example, if you have the following scene tree:
- Root_Node (has script
root.gd
)
- * Child_Node (has script
child.gd
)
root.gd
script:
extends Node
func _ready():
var child = get_node("Child_Node")
child.counter += 1
print ("child node counter is: ", child.counter)
child.gd
script:
extends Node
var counter = 0
You just need to have a reference to the node with the script, and then you can access any of the variables and functions in GDScript. Hopefully this helps a bit :smile: