-1

so Im making a wave shooter game and I got these bugs that I do not know how to fix this it says unexpected indentation and Ive tried every possible solution yes I do know that gd script is similar to python and its indent sensitive don't tell me plz anyway heres the code:

extends Sprite

var speed = 75

var velocity = Vector2()

var stun = false
var hp = 3

var blood = preload("res://blood.tscn")

    if hp <= 0:
        if Glob.camera != null:
            Glob.camera.screen_shake(120, 0.3)
        
        Glob.points += 1
        if Glob.node_creation_parent != null:
            var blood_part = Glob.instance_node(blood, global_position, Glob.node_creation_parent)
            blood_part.rotation = velocity.angle()
        queue_free()
        print(Glob.points)
    

func basic_move_towrds(delta):
    if Glob.player != null and stun == false:
        velocity = global_position.direction_to(Glob.player.global_position)
    elif stun:
        velocity = lerp(velocity, Vector2(0, 0), 0.3)
    global_position += velocity * speed * delta
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

When you get "unexpected indentation" means you changed indentation to the right, but there wasn't a statement to justify it.

For example:

func example_func() -> void:
    print("something")
     print("something else") # <- error: unexpected indentation

In general, you need an statement for the indentation to increase:

func example_func() -> void:
    print("something")
    if whatever:
        print("something else")

And if there is an statement, the indentation must increase. Thus, this is also an error:

func example_func() -> void:
    print("something")
    if whatever:
    print("something else") # <- error: expected an indent block

Without an statement, the indentation should not increase at all:

func example_func() -> void:
    print("something")
    print("something else")

The exceptions are expression expanding multiple lines (which could be either using / at the end of the line, or multiline brackets or parenthesis).

If you just read your code and see where the indentation changes, you would pick on those cases where the indentation changes where it should not.


In this case:

var blood = preload("res://blood.tscn")

    if hp <= 0:

Why is that if to the right? It is inside of what?

In fact, GDScript does not support top level statements. That if statement must be placed inside of a func.

I'll venture to guess that code should be inside gunc _process(_delta:float) -> void:.

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • it worked thank you and but I also have one more error – Noah Anaya Jul 16 '21 at 05:12
  • the error is that "basic_move_towards" is not declared under the current class and Ive tried everything I can to fix it – Noah Anaya Jul 16 '21 at 05:15
  • heres the code in the script: extends "res://enemy_core.gd" func _process(delta): basic_move_twords(delta) func _on_hurtbox_area_entered(area): if area.is_in_group("Enemy_Damager") and stun == false: modulate = Color.white velocity = -velocity * 4 hp -= 1 stun = true $stun.start() area.get_parent().queue_free() func _on_stun_timeout(): modulate = Color("ff5d50") stun = false – Noah Anaya Jul 16 '21 at 05:16
  • @NoahAnaya I suppose you are trying to call a function you declared, because there is no such func in Godot API. If you didn't declare it… Well, that is why it does not exist. Also, you seem to have a typo, is it "basic_move_twords" or "basic_move_towards"? That would be another reason why it does not exist: it exists but with a different name. There is also a chance that you declared it somewhere else - I would have no clue where, and the problem is getting a reference to that. funcs are not global. The closer you get is an static func. Second closer is a func in an autoload. – Theraot Jul 16 '21 at 05:24
  • @NoahAnaya I am also under the impression that you are copying parts of code from other places (your code seems complex for somebody struggling with syntax, indentation, scope). Perhaps you copied it wrong, and it was something like "basic.move_towards" or something like that. Again, I would have no way to know. Edit: regardless, I think this other problem you are facing could be a new question, there you would have more space to post the code and any relevant context. – Theraot Jul 16 '21 at 05:27
  • yes I am that, code you see is me following a tutorial because I have no idea how to start game development – Noah Anaya Jul 16 '21 at 15:59