please help me complete this level:
Level 7,Wood Forest
thks
why my hero is died?
2021-08-10T04:04:00Z
hey can you give the specific level like Nine gems example.
Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!
Can you please post your code? And then we will be able to help you. Thanks!
while true:
enemy = hero.findNearestEnemy
if enemy:
hero.isReady(“cleave”)
hero.cleave(“enemy”)
else:
hero.attack(“enemy”)
Why does the 2nd time hero have to wait to cleave??
I noticed several problems:
- In the
enemy
variable, you forgot the()
afterhero.findNearestEnemy
-
isReady()
is a function that returns true or false. When you useisReady
on it’s own, it means nothing. You need to use it in a if likeif hero.isReady("cleave"):
so it checks ifisReady("cleave")
is true. - The if/else says if there’s an enemy, cleave, else, attack. It should be
if enemy:
if hero.isReady("cleave"):
cleave
else:
attack
No, at their level, it shouldn’t be that code yet.
@Khoa_Tr_n, you are not indenting your code whatsoever. You must indent everything after while true:
, if enemy
And else
.
I think your code is perfect. You just need to indent it.
When you don’t format your code, it doesn’t indent.
Ok.
Can you please format your code using the </> button. This way we can see your code in full.
After you click that paste your code!