I'm stuck at CS3. 57- Pet engineer

CodeCombat - Coding games to learn Python and JavaScript

Protect the camp from ogres.

The event handler for the pet’s event “hear”.

def hearGuards(event):
# Find guards to listen them.
archer = pet.findNearestByType(“archer”)
soldier = pet.findNearestByType(“soldier”)
# If the speaker is the archer:
if event.speaker == archer:
# Move to the left button.
pet.moveXY(32, 30)
# If the speaker is the soldier:
if event.speaker == soldier:
# Move to the right button.
pet.moveXY(48, 30)

pet.on(“hear”, hearGuards)

You don’t have to change code below.

Your hero should protect the right bottom passage.

while True:
enemy = hero.findNearestEnemy()
if enemy:

can someone help me? im stuck at this level for a while now. i dont know why my code are incomplete

Hello, Dree_123
instead of just using:
if enemy: hero.attack(enemy)

Try using checks like if-distance-from-enemy < 20 & changing the hero to a warrior.

Should help
– Yashins

“You don’t have to change code below.”

1 Like

Please remember to format your code!:grin: