Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help On Backwoods Brawl pt.2

This is my first post so in advance thanks to anyone who helps me. ↓↓This is my code below↓↓

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Use if to make sure enemy exists before checking its distance.
distance = hero.distanceTo(enemy)
if distance < 5:
if hero.isReady(“cleave”):
else:
hero.attack(enemy)

It keeps on saying: “else must be paired with an if.” Please help

Hi Zayn,

I could be wrong, but I think that your “if” statement is wrongly formatted. It should be-

if (enemy) {

Furthermore, others will be quick to tell you – and rightly so – to make sure that when you post code, to do so by putting the ` symbol (normally found in the upper left corner) three times before and after your code so it automatically formats in a proper code form. For example:

while(true)
enemy = hero.findNearestEnemy();
if (enemy);

I hope that helps.

@bobmcphe thank you this has helped me except, now it is telling me: “Empty if statement. Put 4 spaces in front of statements inside the if statement”. it shows an exclamation mark on line 12. My CUrrent code below:

# Stay alive for one minute.
# If you win, it gets harder (and more rewarding).
# If you lose, you must wait a day before you can resubmit.
# Remember, each submission gets a new random seed.
while True:
    enemy = hero.findNearestEnemy()
    if (enemy):
        # Use if to make sure enemy exists before checking its distance.
        distance = hero.distanceTo(enemy)
        if distance < 5:
            if hero.isReady("cleave"):
            else: 
                hero.attack(enemy)

I am not sure which is line 12, but I suspect the format for:

if distance < 5: 

is wrong. Also, the else tag I am pretty sure should be using a { instead of a :

But, double check what I am saying. I am not 100% sure. You have a menu in the middle of your screen, which actually gives you either the exact code, or a similar version, which shows the syntax and format.

Sorry, I should have said where line 12 is, it is where the “else” is. The distance is not the problem.

You need a command if cleave is ready before the else statement. What do you do if cleave is ready?