I have had a lot of trouble with this block in the past, so i assume other people are having trouble with it to.
so, i used to think this peice of code will just cleave when its ready when you put it down, for example
while True:
hero.isReady(“cleave”)
hero.attack(enemy)
but it does not work like this. Hero.isReady(“cleave”) is a IF statement. so try this
while True:
enemy = hero.findNearestEnemy()
if enemy:
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)
that is how it works. hope this helped!
1 Like
@sonicrosebeam- Would this Python code be helpful in Level 2- the Stillness in Motion level? My eleven year old daughter hasn’t been working on Code Combat because of her hero being attacked by the ogres, even though her hero fights like crazy with her sword! Since she’s getting used to a new school and starting middle school, she hasn’t had much time to think about this, but I feel that is she had some advice, she could work through this level! Thanks for any advice!
1 Like
this level is tough, but i can help.
if a ogre is near you, you have to attack.
so if you put
if self.distanceTo(enemy1) < 5:
hero.attack(enemy)
like a if loop, it should work. but, does it only work once? thats where a loop comes in.
loop:
if self.distanceTo(enemy1) < 5:
hero.attack(enemy)
but we dont know what the enemy is! so we have to find it
loop:
distance = enemy
enemy = hero.findNearestEnemy()
if self.distanceTo(enemy1) < 5:
hero.attack(enemy).
but what do we do if there is no enemy?(optional)
else:
shield
i hope this helps!
ps: you can use cleave, but its up to you!
Thank you so much, Shino, for taking the time to help out my daughter. She hasn’t played Code Combat for a while, since starting a new STEM school for middle schoolers, where they are going to learn Python coding next semester! Right now she is trying to learn Spanish, which seems a lot like coding practice to me! I have printed out your suggestions, and I will keep them for her, so when she feels she is ready to try this level again, then your coding advice will definitely come in handy! I wish the moderators would give the correct code, if a coder has honestly tried and gotten help, I think that is one reason people give up on coding, if they are not going to a school that teaches it!
Thanks again,
Camicazi
1 Like