#What is wrong with this

1 messages · Page 1 of 1 (latest)

stoic cloud
#

This is my first time opening up Godot and coding

I copied this code from some guy in yt.

This is for 2d top down movement, and I don't know what's the error. I asked chatgpt and bard about it, and yet there's still an error/

extends CharacterBody2D

var speed = 200
var velocity = Vector2()

func _ready():
pass

func _physics_process(delta):
    velocity = Vector2()
    
if Input.is_action_pressed("right"):
    velocity.x += speed
if Input.is_action_pressed("left"):
    velocity.x -= speed
if Input.is_action_pressed("top"):
    velocity.y -= speed
if Input.is_action_pressed("down"):
    velocity.y += speed
    move_and_slide(velocity)
    look_at(get_global_mouse_postion())
#

Line 9:Standalone lambdas cannot be accessed. Consider assigning it to a variable.
Line 13:Expected statement, found "Indent" instead.
Line 14:Unexpected "if" in class body.
Line 14:Unexpected "Indent" in class body.
Line 15:Expected end of file.

mellow thornBOT
#
Embedding code in discord messages
Inline Code

When you surround some words with single backticks like `this`, it will be formatted as code.

Code Blocks

You can also include code blocks by surrounding the code with three backticks. If you add "swift" then you will also get basic syntax highlighting:
```swift
print("hello world")
```
Discord will then show it as a code block like this:

print("hello world")
Upload

If your code snippet is rather long, you can upload it to a text paste site. One option that supports syntax highlighting for GDScript is https://bpa.st/

fluid sluice
#

which version of Godot do you use? For which version is the yt video?

stoic cloud
#

4.3

stoic cloud
fluid sluice
#

move_and_slide() is used without an argument

stoic cloud
#

What is wrong with line 9

stoic cloud
fluid sluice
#

the indentation is wrong, remove the tab left from func _physics_process

stoic cloud
fluid sluice
stoic cloud
#

I see i see

fluid sluice
stoic cloud
#

How about this now?

stoic cloud
#

Im just trying to open up myself in coding

fluid sluice
#

in 4.x CharacterBody2D already has velocity built-in

#

remove the line

stoic cloud
fluid sluice
#

by accessing it. But you don't have to define it as new variable

stoic cloud
#

I see

stoic cloud
fluid sluice
#

spelling

stoic cloud
#

Oh i did not notice that

stoic cloud
#

What's a parser error

fluid sluice
#

sorry, I ignore blurry photos from now on. Please start with the official tutorial. I guess the video is for Godot 3.x

stoic cloud
#

Alright alright. I'm just trying to open up coding to myself first.

stoic cloud
#

Anf the code is not working except for the down movement