[SOLVED] Kithgard Brawl HELP


#1

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.


#2

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


#3

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


#4

You need to check if there is an enemy.


#5

@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.


#6

Please format your code according to the FAQ. It helps us understand what is wrong with your code


#7

Thanks guys, not sure how I overlooked that.


#8

[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.


#9

Please don’t post any correct code.


#10

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.


#12

Please don’t post off topic posts.


#13

These codes above are helper ones or wrong ones.


#14

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