[SOLVED] Village Rover Help

# This defines a function called findAndAttackEnemy
def findAndAttackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

# This code is not part of the function.
while True:
    # Now you can patrol the village using findAndAttackEnemy
    hero.moveXY(35, 34)
    findAndAttackEnemy()
    enemy = hero.findNearestEnemy()
    hero.attack(enemy)
    # Now move to the right entrance.
    hero.moveXY(60, 31)
    # Use findAndAttackEnemy
    hero.findNearestEnemy()
    hero.attack(enemy)
    

I am stuck

Can you send me the link? And can you tell us your problem?
Lydia

# This defines a function called findAndAttackEnemy
def findAndAttackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

# This code is not part of the function.
while True:
    # Now you can patrol the village using findAndAttackEnemy
    hero.moveXY(35, 34)
    findAndAttackEnemy()
    hero.attack(enemy)
    # Now move to the right entrance.
    hero.moveXY(60, 31)
    # Use findAndAttackEnemy
    enemy = findNearestEnemy()
    if enemy:
        hero.attack(enemy)

It keeps saying that

Try putting

enemy = hero.findNearestEnemy()

At the top of the

while True:

Lydia

1 Like

It says the same thing

try putting it just under the while True:

Try putting it like this

while True:
    enemy = hero.findNearestEnemy()

And then put this

if enemy:
  findAndAttack(enemy)

In place of

findAndAttack(enemy)
hero.attack (enemy)

because in

findAndAttack (enemy)

it already attacks the enemy for you, so why do you need to put

hero.attack (enemy)

again?
Lydia

1 Like

does it work now? @Zoe_Witte

Yes it worked thanks.

2 Likes

Congrats! Can you put someone as the little check mark next to someones comment?
Lydia

1 Like

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