0 votes

I want to press a button to set the value of a variable in other script and and execute an order on depending on the value it returns.

For this I have used the following script

player.gd

var difficulty = get_node("HUD").get("NormalMode").difficulty

But Godot says: Node not found: HUD.

I try with other paths like ("Main/HUD"), ("root/Main/Hud"), ("/root/Main/Hud"), ("/Main/Hud"), ("../HUD"), ("/HUD").

But always says that the node cannot be found or that absolute paths cannot be used

Mi Project Tree is this

Main.tscn is in the same folder of HUD.tscn

What it's wrong?
I must say that I have the exact same route Nodes as in the example game Dodge the Creeps

in Engine by (26 points)

1 Answer

0 votes

The solution in case someone has the same problem is use the onready before the variable since it is not in any function

Thus remaining the code finally:

onready var difficulty = get_tree().get_root().get_node("Main/HUD").get("NormalMode").difficulty

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