How to get a variable from another node script

Godot Version

4.2

Question

so this has been answered before but i dont understand what im doing wrong

the answer was
$HUD/Settings.show_fps

and so i tried
$player.osition [node name then variable name]
$player/setting.osition

but those havent worked [tried capitilizing as well]
and i dont understand other peoples code

child:

extends Node2D

@export var m_message = "Hello, world!"

func _ready():
	pass # Replace with function body.

parent:

extends Node2D

func _ready():
	var v_child = get_node("Child")
	print (v_child.m_message)

1 Like

does it have to be a child node?

no it doesn’t

1 Like

are you sure?

so what im doing is i have 1 node player trying to pass information to another node clone

clone and player are 2 different node (not attached at all

extends CharacterBody2D

func _ready():
	var player = get_node("player")
	print(player.array)

@export var array =[ ]
func _physics_process(delta):
if Input.is_action_pressed("ui_accept"):
		array.append(self.position) 
		array.push_back("done")

i even changed the physics function to _ready and it still doesnt work

ok so it only works if they are parent child node (nodes in the same scene)

if i were to search for tree then node would it work across scenes?

FOUND IT
if you right click a child node you can make it its own scene
so it has its own gd and tcsn but since its still a child node the code above still works

thank you shrooms for your code

do be careful though cause I’ve manage to make this break (so add this in early or be ready for many null errors)

if you have any question then reply to this and ill do my best to answer