HELPPPP Says enemy is undefined (the final kithmaze)

Here is my code for the final kithmaze. It keeps saying that enemy is undefined. I have reloaded and everything but it just keeps saying that enemy in line 4 is undefined. HOW DO I MAKE THIS STOP. Please help

loop:
    self.moveRight()
    self.moveUp()
    self.moveRight()
    enemy = self.findNearestEnemy()
    self.attack(enemy)
    self.attack(enemy)
    self.moveDown()
    self.moveDown()
    self.moveUp()

Enemy on line 4 is undefined? But you use it on line 6. Are you sure that that’s the error message you have? The code seems right to me.

I just loaded your code and into that module and it worked fine for me.

Did you purchase and equip the Mahogany Glasses?

Good point. One issue with the earlier levels is that they assume you don’t have better equipment than a beginner would have at that stage. So if you equip something that doesn’t have self.findNearestEnemy(), you don’t get a warning about it on the equipment screen.

sorry, I had the wrong lines. It said that enemy was undefined when I said that enemy = self.findNearestEnemy()

it says that enemy on line 5 is undefined in

enemy = self.findNearestEnemy()

Can you double-check to make sure that you have the glasses equipped? I’m not really sure what’s going wrong here; the code is fine, but the error message is strange.

yeah my hero is wearing the mahogany glasses

The mahogany glasses need enemy = self.findNearest(self.findEnemies()). You might have an easier time with the crude wooden glasses for now.

oh okay thank you so much. it is working now

loop:
        self.moveRight()
        self.moveUp
        enemy = self.findNearestEnemy(); 
        self.attack(enemy)
        self.attack(enemy)
        self.moveDown()
        self.moveDown()
        self.moveUp()

Merged doublepost

That works great! Are you happy?