0 votes

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.

in Engine by (243 points)

1 Answer

+3 votes
Best answer

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.

by (20,923 points)
selected by

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!

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 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 webmaster@godotengine.org with your username.