# 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
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
does it work now? @Zoe_Witte
Congrats! Can you put someone as the little check mark next to someones comment?
Lydia