system
January 11, 2023, 3:27am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
mikbauer
my code is Control.gd
onready var modeNameLabel = get_node("/root/HUD/Panel/sections/SectionScore/modeName")
func setupHUD():
modeNameLabel.text=modeNames[MOD] <--- error
error:
Invalid set index ‘text’ (on base: ‘Nil’) with value of type ‘String’.
Scene structure:
Control
-HUD
–Panal
—sections
----SectionScore
-----modeName
what should I set the path to access nodeName
I also tried
onready var modeNameLabel = get_node("HUD/Panel/sections/SectionScore/modeName")
mikbauer | 2023-01-11 03:29
system
January 11, 2023, 4:07am
2
Reply From:
jgodfrey
If the script is attached to the Control
node in your tree (as outlined above), then I’d expect that second attempt (posted in your comment) to work - assuming there are no typos in the path as compared to the node names.
Really, any of the following should work:
get_node("/root/Control/HUD/Panel/sections/SectionScore/modeName")
get_node("HUD/Panel/sections/SectionScore/modeName")
$HUD/Panel/sections/SectionScore/modeName
If those don’t work, there’s either a typo in the above path (as compared to your scene tree) or the script is not attached to the Control
node.
Also, you can simply drag the node from the scene tree into your script to see its “path” in text form.
jgodfrey | 2023-01-11 04:09
I had the calling function in _init() and it was not working, but when I put it in _process(delta) it worked
mikbauer | 2023-01-11 04:23