# This function attacks the nearest enemy.
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
# If an enemy exists:
if enemy:
# And if "cleave" is ready:
if hero.isReady("cleave"):
hero.cleave(enemy)
pass
# In your main loop, patrol, cleave, and attack.
while True:
# Move to the patrol point, cleave, and attack.
hero.moveXY(35, 34)
findAndCleaveEnemy()
findAndAttackEnemy()
# Move to the other point:
hero.moveXY(60,31)
# Use findAndCleaveEnemy function:
hero.findAndCleaveEnemy
# Use findAndAttackEnemy function:
hero.findAndAttackEnemy
enemy = hero.findNearestEnemy()
if enemy:
hero.cleave(enemy)
hero.attack(enemy)
else:
hero.attack(enemy)
I don’t see any problem but it marks me incomplete.
# This function attacks the nearest enemy.
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
# If an enemy exists:
if enemy:
# And if "cleave" is ready:
if hero.isReady("cleave"):
# It's time to cleave!
hero.cleave(enemy)
# In your main loop, patrol, cleave, and attack.
while True:
# Move to the patrol point, cleave, and attack.
hero.moveXY(35, 34)
findAndCleaveEnemy()
findAndAttackEnemy()
# Move to the other point:
hero.moveXY(60, 31)
# Use findAndCleaveEnemy function:
hero.findAndCleaveEnemy
# Use findAndAttackEnemy function:
hero.findAndAttackEnemy
findAndCleaveEnemy()
# Use findAndAttackEnemy function:
findAndAttackEnemy()
findAndCleaveEnemy() and findAndAttackEnemy() are not methods of the hero. They are functions that tell the hero what to do. Define a function, then execute the function. The function here tells the hero to cleave if the hero is ready. It also tells the hero to attack the enemy if there is an enemy. Instead of writing it out each time in the while true loop, you can define it as a function and execute the function.