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

does it have to be a child node?

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

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.