For some reason, I have been stuck on this level for so long, and I can’t seem to fix this problem. Every single time, after 35 seconds, the hero will go to attack, and then it always says, “But it’s dead!” I don’t understand, because I have an if statement checking if the enemy exists. Please help me!
# Use your new skill to choose what to do: hero.time
while True:
# If it's the first 10 seconds, attack.
if hero.time < 10:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pass
# Else, if it's the first 35 seconds, collect coins.
elif hero.time < 35:
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
pass
# After 35 seconds, attack again!
else:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pass
Nevermind! I had my friend help me with it, and if anyone else is having this problem, here is the code I have.
# Use your new skill to choose what to do: hero.time
while True:
# If it's the first 10 seconds, attack.
if hero.time < 10:
enemy = hero.findNearestEnemy()
if enemy:
if enemy.type != "palisade":
hero.attack(enemy)
# Else, if it's the first 35 seconds, collect coins.
elif hero.time < 35:
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# After 35 seconds, attack again!
else:
enemy = hero.findNearestEnemy()
if enemy:
if enemy.type != "palisade":
hero.attack(enemy)
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! 
We’re so glad you passed this level! However, I’m going to ask you to remove the code that works. This forum is not meant to give people answers because that’s technically cheating. All we do is give them hints to improve their code.
2 Likes
Sorry to interrupt you, but can you delete that post? People might copy it for cheating through.
2 Likes
This was 5 months ago, maybe don’t post here?
I don’t even think they’re even active now.
3 Likes