Super Noob problem

Godot Version

Godot.4.6.1

Question

Hello! I just started learning to use Godot through youtube tutorials. In one point the teacher says you can find the route to the hud in a function

@onready var hud = get_node(““)

Cool. Just open the game and the remote/local tabs are now visible. Perfect. And then: My root folder is empty. Witchcraft, I suppose.

The local tab is okay, with all the tree(technical word I haven’t learn, ofc) but the line gives me error when I just type the same as the video ‘cause the route isn’t through root.

I have never ever programmed (not even a VHS). Don’t be rude, pretty please.

Thanks!

There is a simpler way to set up a node that you can access.

  • Select the node in the tree.
  • Drag the node to the script.
  • Press the ctrl button and drop the node in the script.

It should look like this:

@onready var node_name: NodeType = $NodeName

Godot automatically figures out the path for you.

If you plan on moving the mode around, consider making the node name unique. That allows the path to auto-update.

1 Like

Thanks for your answer!

I tried and an error message popped. I translated with google (my program is not in english ^^’)

Nodes cannot be dropped because the script 'player.gd(*)' does not inherit from the Node.

And nothing happened. The remote root file is still empty.

The screen shot you posted shows an error that will keep the program from working. The red text where it says “Expected indented block for property…”

Remove the colon ( : ) from line 10.

As for the error message you posted there are two things you need to be aware of - the (*) after the file name means it hasn’t been saved. Any changes you made will not be seen.

The other is you may have a mismatch between the node you are using and the script. It will be easier for people to diagnose if you post a screen shot of the scene tree with the node highlighted. Also please post the code as text in a ``` block - it makes it easier to copy when suggesting a change.

1 Like

Thanks! That worked! Now I can play the game, but when I try to enter on the collision area of the coin, the game stops and gives me two errors. The first is about line 10 and the second about line 15.

In the video, the line 10 was written with the colon, is that a change on the last update?

Sure! Thank you!

You are getting the errors because the CanvasLayer node is not found. You need to fix the path reference. Try deleting the argument to the get_node method and dragging the CanvasLayer node to the argument for the method.

The error you saw with the colon is behavior that has been around since I started using Godot.

I don’t recognize the node you are using for the root of the scene tree, but if it is not derived from a Node2D then you could be causing trouble for yourself.

I suggest that instead of starting with YouTube, you pull some Godot projects off of GitHub and look at them. I used this one when I first started out: GitHub - godotengine/godot-demo-projects: Demonstration and Template Projects · GitHub

1 Like

Thank you so much for your time. You are trully helpful!

Gonna try GitHub. I’m motivated, but unexperienced in logic language.

Wish me luck!