Why does this code has errors?

4.2.1

Im working on the player script and this code

onready var head = $Head
onready var aimcast = $Head/Camera/AimCast
onready var muzzle = $Head/Gun/Muzzle
onready var bullet = preload("res://scenes/Bullet.tscn")

has the error

Parse Error: Unexpected “Identifier” in class body.

Hi, try placing quotations after the dollar sign.

onready var head = $”Head”
onready var aimcast = $”Head/Camera/AimCast”
onready var muzzle = $”Head/Gun/Muzzle”

I have never used quotation like that but the code worked just fine. Is it necessary?

replace onready with @onready

2 Likes

No. Only when the name of your node starts with a number or any of the nodes in the path include white spaces.

1 Like

I just noticed if the node’s name has a white space in it the quotations are necessary

No, this is 4.2, not 3.x

yes , that’s why i said

1 Like

My bad :slight_smile: read it backwards

1 Like

dont worry, mistake can happen anytime

1 Like