[SOLVED] What am i doing wrong

def inAttackRange(enemy):
    distance = hero.findNearestEnemy()
    # Almost all swords have attack range of 3.
    if distance <= 3:
        return True
    else:
        return False

# Attack ogres only when they're within reach.
while True:
    # Find the nearest enemy and store it in a variable.
    enemy = hero.findNearestEnemy()  
    # Call inAttackRange(enemy), with the enemy as the argument
    # and save the result in the variable canAttack.
    if enemy:
        hero.canAttack = inAttackRange()
    # If the result stored in canAttack is True, then attack!
    hero.isReady("cleave")
    hero.cleave(enemy)
    pass

i keep on getting errors please help me out
@_Codemaster @qwerty @Falcons118

image
here is my updated code

Summary
    distance = hero.findNearestEnemy()
    # Almost all swords have attack range of 3.
    if distance <= 3:
        return True
    else:
        return False
# Attack ogres only when they're within reach.
while True:
    # Find the nearest enemy and store it in a variable.
    enemy = hero.findNearestEnemy()  
    # Call inAttackRange(enemy), with the enemy as the argument
    inAttackRange(enemy)
    # and save the result in the variable canAttack.
    if enemy:
        hero.canAttack = inAttackRange()
    # If the result stored in canAttack is True, then attack!
    hero.isReady("cleave")
    hero.cleave(enemy)
    pass

sorry I cant help I am on java script but let me try

You can just find nearest enemy attack it do that 5 times and your done

Change the variable hero.canAttack to canAttack.

you haven’t defined what canAttack is.

it has been solved by @milton.jinich thank thou

@Deadpool198 could you close this topic please

You should try solving the level how you are supposed to do it.

but i alreadly passed it

The point of codecombat is to learn coding, so if you don’t understand something, go back and do it so that you learn how to properly code.

I will close automatically @ZAX155

okay thank @milton.jinich

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.