How to get a variable from another node script

Godot Version



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

the answer was

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

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


extends Node2D

@export var m_message = "Hello, world!"

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


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")

@export var array =[ ]
func _physics_process(delta):
if Input.is_action_pressed("ui_accept"):

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?

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