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