World Two | Level: Shield Rush | Help Please


#1

I’m working on code, and I come across this level and I can’t figure it out. Help anyone?

Python, World two, the level is Shield Rush. Here is my Code:

loop:
    if self.isReady("cleave"):
    enemy = self.findNearestEnemy()
    self.cleave(enemy)
 else:
        self.shield()
        self.attack(enemy)

Thanks!

-j3qx7


#2

Hello, Zachary, and welcome. Please read the FAQ before you post again, so that you learn how to format your code properly. I’ve done it for you this time, but do so yourself in the future.

Phrases like “I need help!” or “This code doesn’t work!” don’t give us what problem you’re having. For future reference, next time give us more description of your error. However, here is what I can see off the top of my head:

Your indentations are a little mixed up. You need to indent lines 3 and 4 one level forward, and put the else on the same level as the if. Secondly, you only define enemy if "cleave" is ready. Therefore, when "cleave" is not ready, enemy is undefined, but you try to attack it. Move the definition of enemy out of the if-statement into the main loop. That should fix your problem.


#3

It Worked! Thank you so much. Next time ill read the FAQ. Thank You!

-j3qx7