as an instance of fireball which is in the main scene change the value of the child node of the parent player

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

I have a player in the main scene that adds a fireball along with the player to the main scene
however I want this in the fireball code to change the value of the child node from the parent player

i found a solution

get_parent (). get_node ("KinematicBody2D / CanvasLayer / Control / GMP"). value + = 10 # get_parent () == level, KinematicBody2D == player

but is it possible not to use an absolute path?

:bust_in_silhouette: Reply From: Inces

Programminst avoid using absolute paths, because it makes nodes stiffly dependent on their scene tree allocation. If You were to decide some day, that You want player to be child of a different node, or You would want to add node inbetween nodes - You will have to change all of the absolute paths in whole your code, because they will start to crash your project.

Generally You want to call and change values of other nodes at short distances ( parent - child ), but when you want to pass information along whooole scene tree, like in your example : use signals !!

translator error, I asked you can use something else instead of the absolute path

F0remNKB | 2021-09-22 21:52

You can and You should use signals for that. Read documentation about them. The way it works is your Fireball emits a signal with some information when you want ( for example if enemy is hit emit signal how many hit points it took form enemy ) and other nodes can listen to that signal. You can imagine it as radiostation - You make anouncement in radio, that you want to hire someone, and people who are intereseted will hear this and come to you.
normally listening to signal requires nodes to be connected to each other, and this also requires absolute path. However You don’t need any paths if You use Autoload script as signals mediator ! ( read about it in documentation )

Inces | 2021-09-23 18:52