Describe the project you are working on:
A game
Describe the problem or limitation you are having in your project:
When I want to create onready variables for nested nodes, I have to repeat the path prefix:
onready var item1 = $Scroll/Grid/Item1
onready var item2 = $Scroll/Grid/Item2
onready var item3 = $Scroll/Grid/Item3
Obviously, this is not good. For example, the path to the Grid node may change and must be changed in all variables.
I can replace this with
onready var grid = $Scroll/Grid
onready var item1 = grid.get_node("Item1")
onready var item2 = grid.get_node("Item2")
onready var item3 = grid.get_node("Item3")
But I would like to use a more compact syntax.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Add shorthand expr$NodePath for expr.get_node("NodePath"). Then we can do this:
onready var grid = $Scroll/Grid
onready var item1 = grid$Item1
onready var item2 = grid$Item2
onready var item3 = grid$Item3

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
I haven't looked at how this is implemented, so I don't know.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
It is possible to attach the script directly to the Grid node, but this option is not always acceptable.
Is there a reason why this should be core and not an add-on in the asset library?:
This cannot be done with an add-on, because it affects the GDScript syntax.
Not sure if that's the best possible syntax, but I agree with this being a problem.
If we were to allow this, I think grid.$Item1 (with a .) would make more sense. That said, I can imagine this being difficult to parse.
Obviously, this is not good. For example, the path to the Grid node may change and must be changed in all variables.
This is a matter of using Replace All, so it's not really a big problem.
it's not really a big problem
Yes, you're right, this is just syntactic sugar. But this is a logical continuation of the $NodePath syntax, which is also syntactic sugar.
You can do $"parentNode/childNode" to provide the $ operator with a nodePath that includes slashes. Doing $parentNode/childNode, to me, sounds like asking for trouble from a syntax standpoint. To reduce boilerplate and increase portability in your paths, you can, theoretically, do something like:
onready var gridPath = "thisNode/grid"
onready var item1 = $gridPath+"/item1"
onready var item1 = $gridPath+"/item2"
onready var item1 = $gridPath+"/item3"
You can do
$"parentNode/childNode"to provide the $ operator with anodePaththat includes slashes.
@Tyrannosaurus1234 You may not have known this, but it is not necessary, it even works without the quotes.
var x = "path/to/node"
# In 3.2 these options are equivalent:
$path/to/node
$"path/to/node"
get_node(x)
# In an alternate reality:
$"path/to/node"
$x
$(x)
$("path/to/" + "node")
Basically, I like the option with parentheses because it doesn't break anything.
var grid_path = "Scroll/Grid/"
onready var item1 = $(grid_path + "Item1")
But my option is still more concise:
onready var grid = $Scroll/Grid
onready var item1 = grid$Item1
For reference, quotes with $ are only required for relative paths that use .. or absolute paths:
$"../Player"
$"/root/Game/Level"
Most helpful comment
For reference, quotes with
$are only required for relative paths that use..or absolute paths: