Pull a variable from another script. (3.1.1)

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

I’m wanting to display the “state” variable from player.gd using “world.gd.”

Heirarchy:
world
-----player

The script I’m using is as follows:

$debug/state.set_text(str($player.state))

This returns a null instance error, though. Is there another function to pull that information?

:bust_in_silhouette: Reply From: Ole

In your player.gd:

var state:float = 1.0 setget , get_state
func get_state() -> float:
	return state;

In world.gd:

$debug/state.set_text(str($player.get_state()))
:bust_in_silhouette: Reply From: 9BitStrider

Another example that you should double check your code before spazzing out. Haha. I missed the 1 in debug. Now it works.