+1 vote

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?

in Engine by (197 points)

2 Answers

+1 vote

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

https://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_basics.html?highlight=setget

by (79 points)
+1 vote

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

by (197 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.