0 votes

In the main scene, I have a node (player) that is a scene. I also have a label in the main scene. Every frame I want the label to show a variable inside the player script.

My tree in the main scene
Here is the thing in the main scene, I am trying to use the script in "label" to access a variable in "player"

Godot version v3.5.1
in Engine by (24 points)
edited by

2 Answers

0 votes
Best answer

I finally figured it out after a long day of pondering. I instead added a script to the main scene node and I can use that to access everything in the scene.
enter image description here
Please tell me if this is good practice

by (24 points)
0 votes

Since we don't have your code, it's difficult to help with your situation. This is one example of how things may be written.

# Our player scene which has a script attached to it. The script takes the base properties of the player scene and does something more with it, i.e. they "extend" the node. Our variable, "some_variable", has a value we've made. This property can be accessed through the "." operator. The value of the property can then be set (that is assigned) to the "text" property in the Label.
some_label.text = the_player.some_variable
by (3,144 points)

I'm trying to find a way to locate the player node. I tried directly locating it but it won't let me.

The node is located relative to its place in the scene tree. If the player node is a child of the scene's top-most node, then the script can reference it by using the "$" operator:

some_label.text = $player.some_variable
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 Frequently asked questions and 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 [email protected] with your username.