So I need to change text of my label and I have to write this messy line:
get_parent().get_parent().get_node("UI/Label").text = str(followers)
Any idea how can I get this node in a better way? ( This is the player's scrpt )
So I need to change text of my label and I have to write this messy line:
get_parent().get_parent().get_node("UI/Label").text = str(followers)
Any idea how can I get this node in a better way? ( This is the player's scrpt )
I generally use exported nodepath variables for getting nodes that are not children to the node with the script:
export (NodePath) var path_to_node = null
var _node
func _ready():
if (path_to_node != null):
_node = get_node(path_to_node)
else:
print ("NodePath not set in the Godot editor...")
I do not know if it is the best way, but I've used it for many scripts and it works fairly well.
You can use absolute paths. That is another way.
get_node("/root/Main/UI/Label").text = "Something"
Or you can get the root node like this:
get_tree().get_root().get_node("Main/UI/Label").text = "Something Else"
Hope that helps.