Error on Pet Engineer Level

I am getting an error when I run my code and I do not know why. The error occurs on the very last line: hero.attack(enemy), and reads “Fix Your Code ReferenceError: even is not defined”. This is not a typo in my post, the error says “even is not defined” and not “event”. Also this is in the part of the code that is says I do not need to change. I also checked that I have a sword equipped that supports the hero.attack move.

Move your pet to the left or right button as needed.

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

pet.on(“hear”, onHear)

You don’t have to change the code below.

Your hero should protect the bottom right passage.

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

I found my error. It was actually on the line that says “if even.speaker == soldier:” I left a “t” off of the word “event”. It runs ok now. Anyone know why the error would show on the last line, and not the one with the typo?

1 Like

I suppose it’s because the function onHear is running in the not main thread (event concurrency) and as the result, the parser can’t detect correctly where it was raised.