Stillness In Motion - What am I doing wrong?!


#1

I’m using Python!

    # You can put one if-statement within another if-statement.
    # Be careful how the if statements interact with each other.
    # Make sure the indentation is correct!
    # It's helpful to start with one outer if/else,
    # using comments as placeholders for the inner if/else:
    loop:
        enemy = self.findNearestEnemy()
        # If there is an enemy, then...
        if enemy:
            # Create a distance variable with distanceTo.
            distance = self.distanceTo("Munchkin")
            # If the distance is less than 5 meters, then attack.
            if distance > 5:
                self.attack(enemy)
            self.attack(enemy)
            # Else (the enemy is far away), then shield.
            else:
                self.shield()
            
        # Else (there is no enemy)...
        else:
            # ... then move back to the X.
            self.moveXY(40, 34)

#2

Hello, Joshua, and welcome. Please read the FAQ before you post again. It is essential that you learn how to properly format your code. I have done it for you this time, but you must do so yourself in the future.

Your only problem, it looks like, is the distance variable. You need the distance to the enemy, not from "Munchkin".