HELPPPP Says enemy is undefined (the final kithmaze)


#1

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()

#2

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.


#3

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


#4

Did you purchase and equip the Mahogany Glasses?


#5

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.


#6

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


#7

it says that enemy on line 5 is undefined in

enemy = self.findNearestEnemy()


#8

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.


#9

yeah my hero is wearing the mahogany glasses


#10

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


#11

oh okay thank you so much. it is working now


#12
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?