Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

CS2 24. Village Warder

This function attacks the nearest enemy.

def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pass

Define a function to cleave enemies (but only when the ability is ready).

def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
if enemy:
# And if “cleave” is ready:
if hero.isReady(“cleave”):
hero.cleave(enemy)

In your main loop, patrol, cleave, and attack.

while True:
enemy = hero.findNearestEnemy()
# Move to the patrol point, cleave, and attack.
if enemy:
hero.moveXY(35,34)
findAndCleaveEnemy()
findAndAttackEnemy()
# Move to the other point:
hero.moveXY(60,31)
findAndCleaveEnemy
findAndAttackEnemy

What have I done wrong?

Looks like you are missing the () on the last two functions after you moveXY(60, 31). There might be other issues that we can’t see since it isn’t formatted correctly. The link below will show you how to properly format the code in the forum.