I have problem with @

Godot Version



Hello, I need help, I am trying to put a virtual joystick but when I try to put @onready and @export I get the error

extends CharacterBody2D

@onready var joystick = $“…/Camera2D/Joystick”

var speed = 300

func _physics_process(delta):
var direction = joystick.posVector
if direction:
velocity = direction * speed
velocity = Vector2(0,0)


extends Sprite

@export var max_length = 50 # Clearer variable name
@export var dead_zone = 5 # Consistent naming convention

var is_pressing = false # Using a more descriptive name

func _ready():
# Check if a parent node is necessary. If not, remove the line.
# If a parent is needed, ensure it’s a valid NodePath.
# var parent = $“…”

func _process(delta):
if is_pressing:
var mouse_pos = get_global_mouse_position()
var distance = mouse_pos.distance_to(global_position)

	# Handle dead zone
	if distance > dead_zone:
		# Limit movement within max_length
		global_position = mouse_pos.clamped(global_position - max_length, global_position + max_length)

func _on_Button_button_down():
is_pressing = true

func _on_Button_button_up():
is_pressing = false

what is the error you get?

Is there really 3 dots on this line or is it from the unformatted paste?

@onready var joystick = $".../Camera2D/Joystick"

It doesn’t have three points, it has 2

Ah, godot 4 (which i must assume this script or tutorial is from) requires onready and export to be prefixed with the at sign. Just remove it.

1 Like