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?

Hi Oliver and welcome to the forum! It is best not to comment on a topic that has been inactive for more than a month or so. Chances are, the prior contributors are no longer (not currently) active, so will not see your response.

Your intention to help is much appreciated though! You properly mention that indentation can be critical. In order to see indents here in the forum, please post all code as per this topic: [Essentials] How To Post/Format Your Code Correctly

That will turn what you just posted in to this:

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

It also provides a copy button, so we can copy/paste the code for further testing, if needed:

full version fixed
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”):
ready = hero.isReady(“cleave”)
else:
hero.attack(enemy)

Hi @Stephen_Stanchev and welcome to the forum! :partying_face:

Can you tell me what do you mean with this?

Andrei

1 Like