Dodge The Creeps Error: Unindent does not match any other indentation level

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

I am taking the tutorial for the game “Dodge The Creeps” and i have encountered an error in scripting that i can’t seem to solve. I saw where someone else had encountered a similar error and they got a reply, but i still cannot get it right. I think the tutorial should have a section where it shows the whole script like in the lesson before it, so you can see what they did and solve your problems without posting a question here.

Anyway, here is the code:

extends Area2D

export (int) var SPEED
var Velocity = vector2
var screensize

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

func _process(delta):
    velocity = Vector2()
    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
        $AnimatedSprite.play()
    else:
        $AnimatedSprite.stop()
	
	position += velocity * delta
	position.x = clamp(position.x, 0, screensize.x)
	position.y = clamp(position.y, 0, screensize.y)

For some reason the program is telling me that the end bit where the position is updated has unproper indenting. I don’t know why and i have tried several variations, but they all give the same error. What am i doing wrong?

Sorry for the kinda stupid question, but i’m obviously completely new to Godot and GDscript.

:bust_in_silhouette: Reply From: kidscancode

Nothing looks wrong with the indentation of what you posted, so I suspect you have a copy-and-paste problem.

The Godot editor expects Tab characters for indenting. If you copy-and-pasted the code from the website, it probably inserted spaces. You can see the difference in the editor because the editor by looking for the pale >> symbol which represents the tab character.

I did put in the tab indenting, but the problem was that was the only thing i indented with tab. It’s fixed now, thanks!

lincolnpepper | 2018-03-20 16:06

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