I can't move on to my "Else" statement. what am I missing?

I’m able to use my code to push blocks, and it was working fine, but I wanted to make sure I couldn’t push a block into a wall, or another block. to do that, I added some code…

func _process(delta):

    for body in area_right.get_overlapping_bodies():
        if body.is_in_group("Player"):
            if(hero.get_collision_layer() == 1):
                arrow_left.show()
                if  Input.is_action_just_pressed("Push"): 
                    move_left()

func move_left() -> void:
    for body in area_left.get_overlapping_bodies():
            if(body.get_collision_layer() == 1):
                print("Nope")
            else:
                print("Pushed")
                block.position.x -= 1 * 128

everything from “for body in area_left” to “print(“pushed”)” is what I added. everything works, up to printing “Nope”. but now, a block in front of me or not, I can’t push to the left, or even print the word “pushed”. I’m still pretty new to Godot, and coding, so I’m sure I’m missing something obvious here.

The for loop won’t execute at all if there are no bodies in area left, so the ‘pushed’ code only executes if there’s a body but it’s collision layer isn’t 1.

You could do something like:

func move_left() -> void:
    for body in area_left.get_overlapping_bodies():
            if(body.get_collision_layer() == 1):
                print("Nope")
                return 
           
     print("Pushed")
     block.position.x -= 1 * 128

This way if there’s an obstacle then the function returns early. If no obstacles then the push code after the for loop executes.

Seem like a collision layer problem. Your player and your wall are on the same layer.
Here you check if your player is on layer 1

if(hero.get_collision_layer() == 1):

and after that in your move_left() you don’t want a body in that same layer.

if(body.get_collision_layer() == 1):

Maybe use another layer for the wall and in move_left() check for that other layer.