How to use a Script to change Nodes, while a scene is running?

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

Im trying to get my head around how to use the “Methods” of Nodes like get_tree().get_root() or remove_and_skip or any of them.

To make my problem more comprehensible here some short code where i try to delete a ColorRect and a Label out of the scene.
The SceneTree: Node2d → ColorRect → Label

extends Node2D

onready var a = $ColorRect
onready var s = $Label

func _ready():
    delete_nodes()

delete_nodes():
    get_tree().get_root().remove_and_skip().get_path_to(a)
    get_tree().get_root().remove_and_skip().get_path_to(s)

This is probably completely wrong. I tried to understand the Docs but i got confused, maybe i miss something? help me correct it pretty please and thank you for your time <3

:bust_in_silhouette: Reply From: volzhs

if you want to remove a node and its children node from scene,

a.queue_free()

if you want to remove a node but keep its children node from scene,

a.remove_and_skip()

you don’t need to get_tree().get_root()...