"Unexpected token: if: " and "Unexpected token: Identifier:vel"

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

So i started godot having no idea what the hell im doing then i found the pdf file of the tutorial and downloaded it:
Followed step by step learning functions and made the player node along with sprite and collision configuration, however when i reached the scripting part especially the "movement input i got an error message that i couldn’t find a work around here is the code

#movement input
if Input.is_action_pressed("moved_left"):
vel.x -= speed
if Input.is_action_pressed("moved_right"):
vel.x += speed

I’m also having problems with the reset horizontal velocity as after i type

vel.x = 0 

I get another unexpected token error

If if will help here’s an image:

:bust_in_silhouette: Reply From: kidscancode

“Unexpected token” is what you get when you try to run code outside a function.

Every line of code from line 20 down needs to be indented by one tab, so that it belongs to the process function.

Thank you, the doc must be old. It didn’t give a reason or showed in images to double indent. Much appreciated

EugenioTC | 2022-11-05 17:09