Error: Unindent does not match any outer indentation level

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


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


:bust_in_silhouette: Reply From: kidscancode

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.

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

And sorry for my bad english.

digopauletti | 2018-05-10 14:49

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).

jasonlapier | 2018-11-27 08:25