Having trouble scripting movement

Godot Version

extends CharacterBody2D

export(int) var speed = 80.0

func _physics_process(delta):
var velocity = Vector2.ZERO
if Input.is_action_pressed(“ui_right”):
velocity.x += 1.0
if Input.is_action_pressed(“ui_left”):
velocity.x -= 1.0
if Input.is_action_pressed(“ui_up”):
velocity.y += 1.0
if Input.is_action_pressed(“ui_down”):
velocity.y -= 1.0

Question

I was copying off a video on how to script movement as I am new but the line “export(int) var speed = 80.0” says that there is an unexpected identifier in class body.

You are following an outdated tutorial. If you are a new user to the engine, it’s better to start with the Getting Started part of the documentation here Introduction — Godot Engine (stable) documentation in English it will teach you how to use the editor, the concepts of Godot, and how to structure 2 small games one in 2D and another in 3D.

1 Like

In Godot 4 you would write:

@export var speed : int = 80

This can be also short with “:=”
This way the variable will get the value and the type (int here) from your value.

@export var speed := 80

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.