+1 vote


I'm following this Godot tutorial Your First Game and this error occurred to me:

error(24,1): Unindent does not match any outer indentation level.

Here is my script:

extends Area2D

export (int) var SPEED  # how fast the player will move (pixels/sec)
var screensize  # size of the game window

func _ready():
    screensize = get_viewport_rect().size

func _process(delta):
    var velocity = Vector2() # the player's movement vector
    if Input.is_action_pressed("ui_right"):
         velocity.x += 1
    if Input.is_action_pressed("ui_left"):
        velocity.x -= 1
    if Input.is_action_pressed("ui_down"):
        velocity.y += 1
    if Input.is_action_pressed("ui_up"):
        velocity.y -= 1
    if velocity.length() > 0:
        velocity = velocity.normalized() * SPEED
    position += velocity * delta  // This is the line 24
    position.x = clamp(position.x, 0, screensize.x)
    position.y = clamp(position.y, 0, screensize.y)

What am I doing wrong?
I'm a beginner in python


in Engine by (16 points)

1 Answer

+3 votes
Best answer

This typically happens if you copy-and-paste from the web page, which mixes up the tabs and spaces of the indentation. You'll have to re-indent all those lines yourself.

On a side note, you should try not to ever copy-and-paste. Typing the code out yourself is far more effective in helping to build understanding.

by (21,712 points)
selected by

Thank you so much.
I did not believe was that was it.

And sorry for my bad english.

Expanding on this for others who might be searching for this problem: it is legal to use tabs or spaces, you just have to be consistent. I personally don't like tabs, so I went to the Editor menu, Editor Settings, Indent, and changed Type to Spaces. If you have a mix in a file and you need to convert them, under the Edit menu you can find "Convert Indent to Spaces" (or Tabs).

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.