Can anyone tell me what I've done wrong and help me fix it? I managed to type everything else in, there's just the 1 line that's throwing errors for some reason?

If it makes any difference I'm using version 3.5.2 as the book's designed for version 3.

  • GodotBeginnerRich Change the overarching function from input to _process(delta) or _physics_process(delta) and place at the end there a move_and_slide() so the velocity factor would actually be made use of. Also you should change the area node to a KinematicBody2D. That's the class with the move_and_slide() method.

extends Area2D


# Declare member variables here. Examples:
# var a = 2
# var b = "textvar"


# Called when the node enters the scene tree for the first time.
func_ready(): 
	export (int) var speed
var velocity =Vector2 ()
var screensize = Vector2 (480, 720)
func get_input() :
	velocity = vector2()
	if Input.is_action_pressed ("ui_left") :
		velocity.x-= 1
		if input.is_action_pressed ("ui_right") :
			velocity.x+= 1
			if Input.is_action_pressed ("ui_up") :
				velocity.y-= 1 
				if Input.is_action_pressed ("ui_down") :
					velocity.y+= 1
					if velocity.length() > 0:
						velocity velocity.normalized() * speed

This is getting annoying, I've put the extends Area2D code right at the beginning as instructed and it still doesn't work.

Oh boy, theres a bunch of issues there, but the first one to highlight is that there's some typos there(misplaced and missing spaces). Second, you probably want all those if's to be on the same indentation level.

New problem after getting help with the code on another forum.

Error message is in the image.

Now your indentation is wrong in another manner: all the lines starting from line 10 are on the top level, outside of any functions and the first line in red is missing the if.

You probably want it to be:

	if Input.is_action_pressed("ui_right"):
		velocity.x += 1
	if Input.is_action_pressed("ui_up"):
		velocity.x -= 1
	if Input.is_action_pressed("ui_down"):
		velocity.x += 1
	if velocity.length() > 0:
		velocity = velocity.normalized() * Speed

    Megalomaniak Thanks, that code doesn't give any errors but the character doesn't move.

    I probably need to write some more code to make it move.

    I'll be back tomorrow probably.

      GodotBeginnerRich Change the overarching function from input to _process(delta) or _physics_process(delta) and place at the end there a move_and_slide() so the velocity factor would actually be made use of. Also you should change the area node to a KinematicBody2D. That's the class with the move_and_slide() method.