Get Node from another Node

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

Hello guys!
I have ugly code:

var explabel = get_parent().get_parent().get_parent().get_parent().get_parent().get_parent().get_node("CenterPanelContainer/CenterBoxContainer/ExperiencePanel/ExperienceBox/LabelValue")

It’s work, but it’s ugly! >.< my eyes bleeding whe i see it.

from this view:

HOW CAN I DO IT PERFECTLY BEAUTIFUL? ;D

THANK YOU VERY MUCH!

:bust_in_silhouette: Reply From: CKO

One way is to add a script to the parent node of CenterPanelContainer and RightPanelContainer nodes, pass a reference to this parent to AdvantageB node when initializing and have a method in the parent node that returns the ExperienceBox/LabelValue

Another way is to declare a signal and emit it from AdvantageB node when experience label needs to be update it and and connect the experience node to listen to the signal events

:bust_in_silhouette: Reply From: thirite

get_parent().get_parent().get_parent().get_parent().get_parent().get_parent().get_node(“CenterPanelContainer/CenterBoxContainer/ExperiencePanel/ExperienceBox/LabelValue”)

Holy shit my sides
I would suggest using a central script at the root of the scene with a variable referencing the desired node. eg:

onready var explabel = get_node(“CenterPanelContainer/ExperiencePanel/ExperienceBox/LabelValue”)

Then query from the “searching” node via:
get_parent(“SceneRoot”).explabel