How do I get the parent of a script and use its properties?

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

Sorry for bad english, i’m using Google Translator.

I have a script and I want to know how do I get the parent of the script. I have a Control object, and inside it I have a Label, I have a script inside the Label, and I want to change the Label’s text through the script to a global variable, but I don’t know how to do that, since all the methods I’ve tried don’t worked and there are no pages about it and in the Documentation I found nothing.

When the player enters the game, I have a LineEdit for him to type his name and when he presses Enter, the value of the global variable is set to what he typed. Here is the script:

extends LineEdit

var control: Control

func _on_text_submitted(text: String) -> void:
	var stripped_text = text.strip_edges()
	if stripped_text.length() >= 4:
		PlayerName.change_name(stripped_text)
		print(PlayerName.PlayerName)
		get_tree().change_scene_to_file("res://CenaDestino.tscn")
	

Here is the global variable script:

extends Node

var PlayerName = "Player"

func change_name(name):
	PlayerName = name

Now I need a script so that when the player changes scenes, the text in that scene changes to the global variable, and i want to put that in name_labelThe script goes in name_label

:bust_in_silhouette: Reply From: zhyrin

I’m not sure what you mean exactly. Do you want to access variables and functions of the class your script extends? You have access to all features of an extended class.
If you extend a Label you have direct access to the text variable in your script.

# the script attached to name_label
extends Label

func _ready() -> void:
    text = PlayerName.PlayerName
:bust_in_silhouette: Reply From: matheusmdx

You need to put inside name_label script:

func _ready():
    text = PlayerName.PlayerName
:bust_in_silhouette: Reply From: Lyric

Generally it’s bad to use it because it strongly couples your architecture. So if there will be changes, you have to adjust everything again.
But if you really want to use it here is a link to documentation (get_parent()): Node — Godot Engine (stable) documentation in English
I hope it helps.

:bust_in_silhouette: Reply From: Lyric

Generally it’s bad to use it because it strongly couples your architecture. So if there will be changes, you have to adjust everything again. Try using events instead.
But if you really want to use it here is a link to documentation (get_parent()): Node — Godot Engine (stable) documentation in English
I hope it helps.
(Sorry for the duplicate)