Code query - Errors in code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GodotBeginnerRich

`# 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():
Extends Area2D
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
`I’m having a problem with a script for “Coin Dash” in a book, here’s the code in the pic.

Code

It’s giving an error on line 19.

Can anyone help me fix it?

:bust_in_silhouette: Reply From: jgodfrey

This line…

Extends Area2D

Should be the FIRST line in the file, and needs to be this:

extends Area2D

(note the character case change)

Also, it’s important that you report the actual error you’re seeing (because your image isn’t working in the forum). Also, please format your code for the forum (using the {} button). Since gdscript uses indention-based logic control, it’s impossible to spot certain logic errors in unformatted code.

Ah thanks, I’ll fix that later.

GodotBeginnerRich | 2023-04-17 18:56

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 edited the code as instructed on another forum, and it still doesn’t work.

I know I suck at programming but come on.

GodotBeginnerRich | 2023-04-17 20:13

Errr… There are still a number of obvious errors here. And, you haven’t done anything I mentioned above to help us help you (format your code, post the exact error message)…

Where are you getting this code from? Maybe pointing out the source might be helpful here too.

jgodfrey | 2023-04-17 20:20

The code is for the Coin Dash project in the book “Godot Game Engine Development Projects” by Chris Bradfield, available as a Kindle book and an actual book on Amazon.

I realise I suck at programming but this is getting rather annoying.

GodotBeginnerRich | 2023-04-17 20:38