+2 votes

My game is made of 2 scenes: STAGE and PLAYER.
A have a variable called SCORE in the player script of the PLAYER scene.

I have instanced PLAYER into STAGE and I can play just fine and I can print the variable to the console and it updates perfectly.

The problem comes when I try to print the variable to a RichTextLabel in the STAGE scene so it is visible in the main game.

How can I access the variable SCORE from the RichTextLabel script?

Thank you so much!

in Engine by (78 points)

2 Answers

0 votes

You have to use a singletons.
http://docs.godotengine.org/en/3.1/getting_started/step_by_step/singletons_autoload.html When you have more questions ask me

by (232 points)
+1 vote

One way to do this is by getting the PLAYER node in the RichTextLabel script:

var score = get_node("../Player").score

note that this only works if your node tree looks like this:

- Stage
  - Player
  - RichTextLabel

The ".." in the node path basically refers to the parent node.

by (21 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 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.