Where you can discuss, chat about events or, organise member meetups, the world or life in general including movies, tv shows and more.
Moderators: Beerkeg, Ferefire
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 17 Apr 2023, 20:34
Getting errors in this code.
Code: Select all
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
Can anyone help me fix it?
I don't beee-lieve it!
Rich-Allen1976
-
Beerkeg
- Standard Member
- Posts: 964
- Joined: 05 May 2017, 20:51
-
Contact:
-

-
Quote
-
1
login to like this post
Post
by Beerkeg » 17 Apr 2023, 21:35
I've not written any GDscript or even heard of it, but this doesn't return any errors. Seems like some formatting issues, typos and indenting:
extends Area2D
export var Speed:int
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
Beerkeg
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 18 Apr 2023, 07:00
Beerkeg wrote: ↑17 Apr 2023, 21:35
I've not written any GDscript or even heard of it, but this doesn't return any errors. Seems like some formatting issues, typos and indenting:
extends Area2D
export var Speed:int
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
Thanks, I'll see if this works.
Code: Select all
extends Area2D
export var Speed:int
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
Returns an error on the "if" after vector2()
I don't beee-lieve it!
Rich-Allen1976
-
Beerkeg
- Standard Member
- Posts: 964
- Joined: 05 May 2017, 20:51
-
Contact:
-

-
Quote
-
0
login to like this post
Post
by Beerkeg » 18 Apr 2023, 08:20
richardallen1976 wrote: ↑18 Apr 2023, 07:00
Beerkeg wrote: ↑17 Apr 2023, 21:35
I've not written any GDscript or even heard of it, but this doesn't return any errors. Seems like some formatting issues, typos and indenting:
extends Area2D
export var Speed:int
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
Thanks, I'll see if this works.
Code: Select all
extends Area2D
export var Speed:int
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
Returns an error on the "if" after vector2()
Sorry about that, didn't realize the forum gets rid of the formatting :P
You need to indent your code so 1 tab before velocity = Vector2() and all the if statements and 2 tabs before the if returns. Like in this image (if the image uploads properly)

Beerkeg
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 18 Apr 2023, 08:24
That's very helpful
I'll see if it works later.
Unfortunately the link doesn't work.
Well it does but I have to sign into the website to view the pic.
Would you be able to inbox me the code so I can copy/paste it into Godot?
I don't beee-lieve it!
Rich-Allen1976
-
Beerkeg
- Standard Member
- Posts: 964
- Joined: 05 May 2017, 20:51
-
Contact:
-

-
Quote
-
0
login to like this post
Post
by Beerkeg » 18 Apr 2023, 21:52
richardallen1976 wrote: ↑18 Apr 2023, 08:24
That's very helpful :)
I'll see if it works later.
Unfortunately the link doesn't work.
Well it does but I have to sign into the website to view the pic.
Would you be able to inbox me the code so I can copy/paste it into Godot?
Made a pastebin with it, it kept the formatting there
https://pastebin.com/U4rGBS8Y
Beerkeg
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 19 Apr 2023, 06:04
Beerkeg wrote: ↑18 Apr 2023, 21:52
richardallen1976 wrote: ↑18 Apr 2023, 08:24
That's very helpful
I'll see if it works later.
Unfortunately the link doesn't work.
Well it does but I have to sign into the website to view the pic.
Would you be able to inbox me the code so I can copy/paste it into Godot?
Made a pastebin with it, it kept the formatting there
https://pastebin.com/U4rGBS8Y
Great stuff, you get a Gold star

I don't beee-lieve it!
Rich-Allen1976
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 19 Apr 2023, 06:52
Well I copied/pasted the above code and it gives the following error.
-
Attachments
-

- Error messages
- Screenshot from 2023-04-19 07-50-51.png (165.69 KiB) Viewed 744 times
I don't beee-lieve it!
Rich-Allen1976
-
Beerkeg
- Standard Member
- Posts: 964
- Joined: 05 May 2017, 20:51
-
Contact:
-

-
Quote
-
0
login to like this post
Post
by Beerkeg » 19 Apr 2023, 11:02
I did notice a mistake in my last pastebin, heres the new one
https://pastebin.com/pWsMuWdk
also imgur link for what my output looks like
https://imgur.com/a/kAPO1VJ
I think you're getting the error since you've only indented lines 7-9, but you need it for all of them. If my imgur link works, you can see what I did there. I don't really see anything else that would throw the error.
Beerkeg
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 19 Apr 2023, 17:53
Beerkeg wrote: ↑19 Apr 2023, 11:02
I did notice a mistake in my last pastebin, heres the new one
https://pastebin.com/pWsMuWdk
also imgur link for what my output looks like
https://imgur.com/a/kAPO1VJ
I think you're getting the error since you've only indented lines 7-9, but you need it for all of them. If my imgur link works, you can see what I did there. I don't really see anything else that would throw the error.
Thanks
@Beerkeg, I appear to have sorted it, with the help of a guy on the Godot Community.
But thanks for trying your best to help

I don't beee-lieve it!
Rich-Allen1976
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 20 Apr 2023, 07:02
Code: Select all
extends KinematicBody2D
export var Speed:int
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.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.x += 1
if velocity.length() > 0:
velocity = velocity.normalized() * Speed
Brings up an error, summat about the Area2D not being there.
HELP before I tear up the book and shove it somebody's arse.
I don't beee-lieve it!
Rich-Allen1976
-
Beerkeg
- Standard Member
- Posts: 964
- Joined: 05 May 2017, 20:51
-
Contact:
-

-
Quote
-
0
login to like this post
Post
by Beerkeg » 20 Apr 2023, 09:05
Okay, a few things...
1. Area2D and KinematicBody2D are not interchangeable, they're completely different classes for different purposes. So you can't just use the same bit of code for the other class.
2. What version of the godot engine are you using and what version is your book on? Several things change between versions, for example check out this doc
https://docs.godotengine.org/en/stable/ ... -resources
3. Programming in high-level languages (like C#, GDscript and many others) sucks, because most of the time you're not programming, you're googling for methods and classes, syntax, because all the hard bits of code have been done for you. For example if your book tells you to use Area2D, but hasn't told you what it does, then you look it up, find godot's docs about it and read up on it. It'll tell you what parameters it has, it'll break down all the methods for you and it'll have code examples and tutorials.
https://docs.godotengine.org/en/stable/ ... rea2d.html
Edit: Just noticed they also have example projects you can download where everything is already done and you can play around with the example to better understand what things do
https://docs.godotengine.org/en/stable/ ... ea_2d.html (At the very bottom)
You don't learn to code from a book, you learn it by failing to get something to work again and again until you've learned from all your fails.
Beerkeg
-
Rich-Allen1976
- Dark Blue Member

- Posts: 8202
- Joined: 03 Sep 2022, 14:31
-

-
Quote
-
0
login to like this post
Post
by Rich-Allen1976 » 20 Apr 2023, 14:07
Beerkeg wrote: ↑20 Apr 2023, 09:05
Okay, a few things...
1. Area2D and KinematicBody2D are not interchangeable, they're completely different classes for different purposes. So you can't just use the same bit of code for the other class.
2. What version of the godot engine are you using and what version is your book on? Several things change between versions, for example check out this doc
https://docs.godotengine.org/en/stable/ ... -resources
3. Programming in high-level languages (like C#, GDscript and many others) sucks, because most of the time you're not programming, you're googling for methods and classes, syntax, because all the hard bits of code have been done for you. For example if your book tells you to use Area2D, but hasn't told you what it does, then you look it up, find godot's docs about it and read up on it. It'll tell you what parameters it has, it'll break down all the methods for you and it'll have code examples and tutorials.
https://docs.godotengine.org/en/stable/ ... rea2d.html
Edit: Just noticed they also have example projects you can download where everything is already done and you can play around with the example to better understand what things do
https://docs.godotengine.org/en/stable/ ... ea_2d.html (At the very bottom)
You don't learn to code from a book, you learn it by failing to get something to work again and again until you've learned from all your fails.
The book is for Godot 3, I'm using Godot 3.5.2.
Clearly the author's an idiot.
I don't beee-lieve it!
Rich-Allen1976