Can someone help with my GDscript

Trying to make a game and all the code is fine but then when i add the if Godot says: Unexpected if in class body.

Here is an example of what i am coding;

func _physics_process(delta): pass
var direction = Input.get_vector(“left”, “right”, “up”, “down”)

if direction.x == 0 and direction.y == 0

1 Like

First of all, delete pass. Then, if you start a condition, you must finish it. Something like this:

if direction.x == 0 and direction.y == 0:
    # do something

Indentation is important in GDScript.

2 Likes

You have a “pass” keyword after the _physics_process method declaration. This means that the rest of the code will not be part of the function. Also, the rest of the code seems to be not indented, so Godot thinks that the If statement is not inside a function.

So:

  1. delete “pass” keyword
  2. indent variable declaration and if statement.
  3. add something after the if statement or it will still through an error
1 Like

thank you. but it didn’t work

You’ve made 4 threads on these these few lines of code now. Did you try any of these recommendations? Please elaborate, what “didn’t work”, what does your code look like now? What do you want your code to do?

Make sure to paste with formatting.

```
type or paste code here
```

Results in:

type or paste code here

Previous Thread recommendations

Don’t waste your time with this person, is the case of a person that watch a 15m tutorial and thinks: “Now i can do games!”. I already said for this person he needs to learn the basics before attempt do a game, don’t know the very basics like what’s scope, indetation, etc.

It’s really difficult to help when you don’t cooperate and keep responding with ‘it doesn’t work’. We’re not mind readers. Until you post the entire script, no one will likely be able to do anything about it.