Hi, i am following a tutorial from HeartBeast and i am in the 2 episode. And i wrote the code exactly the same as in the tutorial. But in the 10 line the line is red and is according to goddot wrong. Despite i have writen the entire code exact the same as in the tuorial an there its not red.
Does somabody has an idea why its red?
thats the code:

extends KinematicBody2D

var velocity = Vector2.ZERO

func _physics_process(delta):
	apply_gravity()
	var input = Vector2.ZERO
	input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	
	 if input.x == 0:
		apply_friction() 
	else:
		apply_acceleration(input.x)
		
	if is_on_floor() and Input.is_action_just_pressed("ui_up"):
		velocity.y = -120
		
	velocity = move_and_slide(velocity, Vector2.UP)
	
func apply_gravity():
	velocity.y += 4

func apply_friction():
	velocity.x = move_toward(velocity.x, 0, 10)

func apply_accaleration(amount):
	velocity.x = move_toward(velocity.x, 50 * amount, 10) 

    XWing if input.x == 0:

    and thts the line where its telling me that it is wrong

    1. Which version of Godot are you using?
    2. What is the exact error message? Please copy and paste it here.
    3. To display your code properly here, place ~~~ before and after it.

    i am using the newest avable version on steam. Dont know the exakt version of it but i think its not the new 4.0 version.

    Theres no real error message. When i start the game its a black screen and it says under the code "error(19,1): Unexpected indentation".

     extends KinematicBody2D
    
    export(int) var JUMP_FORCE = -130
    export(int) var JUMP_RELEAS_FORCE = -70
    export(int) var MAX_SPEED = 50
    export(int) var ACCELERATION = 10
    export(int) var FRICTION = 10
    export(int) var GRAVITY = 4
    export(int) var ADITIONAL_FALL_GRAVITY = 4
    
    var velocity = Vector2.ZERO
    
    
    func _physics_process(delta):
    	apply_gravity()
    	var input = Vector2.ZERO
    	input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    	
    	 if input.x == 0:
    		apply_friction() 
    	else:
    		apply_acceleration(input.x)
    		
    	if is_on_floor():
    
    		if Input.is_action_pressed("ui_up"):
    			velocity.y = JUMP_FORCE
    	else:
    		if Input.is_action_just_released("ui_up") and velocity.y < JUMP_RELEAS_FORCE:
    			velocity.y = JUMP_RELEAS_FORCE
    				
    		if velocity.y > 0: 
    			velocity .y += ADITIONAL_FALL_GRAVITY
    
    		
    	velocity = move_and_slide(velocity, Vector2.UP)
    	
    func apply_gravity(): 
    	velocity.y += GRAVITY
    
    func apply_friction():
    	velocity.x = move_toward(velocity.x, 0, FRICTION)
    
    func apply_accaleration(amount):
    	velocity.x = move_toward(velocity.x, MAX_SPEED * amount, ACCELERATION ) 

    thats the status of the code from the tutorial now

    Notice that the "if" is not lined up with the "else". It's indented more. Fix that.

    The "extends" at the beginning is also indented too much, although that might not matter.

    The Godot version should be displayed near the lower right corner of the Editor window.

    You can also use Help >> About Godot to see the version. If you click on the version, it will be copied to the clipboard so that you can paste it here.

    If fixing the indenting solves the problem, then the version doesn't matter.

      At line 19, your “if” has an extra space. Delete the space so it is at the same indentation as the else and then it should work. 🙂

      When you get unexpected indentation errors, look for extra spaces/tabs because Godot is trying to say something does not properly line up.

      Edit: oops, I didn’t see DaveTheCoder reply… I think we were writing at the same time. 😅

        9 days later

        Sorry that i answer after over an week and thanks for the answers. But now i have my next problem. I updatet my game to a newer version but it semi broke the game. All the colision boxes are not right an the pixel stuff is not pixel anymore ane my script is just gone. I wanted to work on the project on the old version but i cant transform it in an older version. Is there any fixes for that?

        Did you make a backup before updating your project to the new version?

        Since the title of this post is pretty vague, if you need help with something in Godot, I just wanna say that I've been asking chat gtp a lot of questions and it's been phenomenal. I pose the question as best I can and if it's not a crazy complex request it produces an extremely helpful response. This has saved me so much time googling stuff.

        14 days later

        yes i have a made backup, and i tried it with chat gpd. But i gave me a response that acceleration is writen wrong but i wrote it wright.

        DaveTheCoder i made thast it no lines up with the else, but now if Input.action_just_pressed.... is red.

         extends KinematicBody2D
        
        export(int) var JUMP_FORCE = -130
        export(int) var JUMP_RELEAS_FORCE = -70
        export(int) var MAX_SPEED = 50
        export(int) var ACCELERATION = 10
        export(int) var FRICTION = 10
        export(int) var GRAVITY = 4
        export(int) var ADITIONAL_FALL_GRAVITY = 4
        
        var velocity = Vector2.ZERO
        
        
        func _physics_process(delta):
        	apply_gravity()
        	var input = Vector2.ZERO
        	input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
        	
        	if input.x == 0:
        		apply_friction() 
        	else:
        		apply_acceleration(input.x)
        		
        	if is_on_floor():
        
        	if Input.is_action_pressed("ui_up"):
        		velocity.y = JUMP_FORCE
        	else:
        	if Input.is_action_just_released("ui_up") and velocity.y < JUMP_RELEAS_FORCE:
        		velocity.y = JUMP_RELEAS_FORCE
        			
        	if velocity.y > 0: 
        		velocity .y += ADITIONAL_FALL_GRAVITY
        
        		
        	velocity = move_and_slide(velocity, Vector2.UP)
        	
        func apply_gravity(): 
        	velocity.y += GRAVITY
        
        func apply_friction():
        	velocity.x = move_toward(velocity.x, 0, FRICTION)
        
        func apply_accaleration(amount):
        	velocity.x = move_toward(velocity.x, MAX_SPEED * amount, ACCELERATION )

          XWing if is_on_floor():

          That if-statement has no body. If the following statements are intended to be its body, they need to be indented.

          how do i intend it? just 4 times space in front of every if and else word or how?

            tab key indents the active line, if multiple lines highlighted then tab indents all the highlighted lines.

            XWing how do i indent it?

            It's easier to use tabs than spaces. Use one tab for each level of indentation. Don't mix tabs and spaces.

            I think most good editors have an option to display tabs via a glyph/icon in the editors.