[SOLVED] Kithgard Brawl HELP

Can anybody tell me why this code is not acceptable in this level. They harp on literally this exact code in the forest levels yet it always fails on this level.

while True:
    enemy = hero.findNearestEnemy()
    if hero.isReady("cleave"):
        hero.cleave(enemy)
    else:
        hero.attack(enemy)

I’ve even tried different variations which are taught in the forest levels like:

while True:
    enemy = hero.findNearestEnemy()
    if hero.isReady("cleave"):
        hero.cleave(enemy)
    else:
        hero.attack(hero.findNearestEnemy())

but no matter what is tells me the hero.attack line should return object but instead returned NULL. This is exactly what has worked in later levels and I have no idea why it won’t work in this earlier level.

add a if(else) {}. and try again.:slight_smile:

and also send a screenshot + your code with it.:grinning:

You need to check if there is an enemy.

1 Like

@Chaboi_3000 is correct. Make sure you wrap the hero.attack command with an if statement. This is because if there is no enemy or all are dead, the system bugs out trying to find one, when there is none in reality. By using this code:

while True:
  enemy = hero.findNearestEnemy()
  if(enemy):
    if hero.isReady("cleave"):
      hero.cleave(enemy)
    else:
      hero.attack(hero.findNearestEnemy())

the system will look for variable enemy. If there is an enemy, you will attack it, otherwise, don’t bother because then you will bug out.

3 Likes

Please format your code according to the FAQ. It helps us understand what is wrong with your code
https://discourse.codecombat.com/faq

2 Likes

Thanks guys, not sure how I overlooked that.

2 Likes

[Please don’t post solutions]
………………………………………………………………………
this is a surefire code that you can use, and for forest, just change the XY and it will work there as well.

1 Like

Please don’t post any correct code.

3 Likes

yep dont post any correct code
it’s a good habit, since it would be more serious if u posted the correct code for harder levels
forest levels are relatively easy to solve, but dont post the solution anyway.
Thankyou.

3 Likes

Please don’t post off topic posts.

1 Like

These codes above are helper ones or wrong ones.

1 Like

Hi there,

The code in the beginning was the user’s code with errors.

The code by _TD_RodYT is code explaining how to correctly check if there is an enemy. Since neither of these are solutions to a level, they’re allowed to stay.

Maka

3 Likes

If you have a Order Of Paladin Ring, this level would be much easier for you (like me). You would also need a strong sword and good armor for protection. With all of those things, I beat the Kithgard Brawl a few times. This is also useful for other replayable levels like this. I’m not so sure about Rangers and Wizards, but it works for Warriors.

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Welcome‌ ‌welcome‌ ‌to‌ ‌the‌ ‌forum!‌ ‌It‌ ‌is‌ ‌a‌ ‌lovely‌ ‌place‌ ‌where‌ ‌you‌ ‌can‌ ‌share‌ ‌all‌ ‌kinds‌ ‌of‌ stuff‌ ‌(appropriate‌ ‌of‌ ‌course),‌ ‌share‌ ‌bugs,‌ ‌and‌ ‌even‌ ‌get‌ ‌assistance‌ ‌for‌ ‌code!‌ ‌We‌ ‌suggest‌ ‌that‌ ‌you‌ ‌review‌ ‌this‌‌ topic‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ this topic‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ :partying_face: :partying_face:
The person who needed help is no longer active so they won’t be able to see your message.
Lydia