The Trials: Why am I not attacking

Hi! My hero isn’t attacking, yet I coded it to attack multiple times. Before, after it attacks, it would just stand there instead of moving torward the mushrooms and collecting them. Why is this happening, and can anyone tell me how to accomplish this level?

This is my code

while True:
if item == hero.findItems():
item = hero.findNearestItem()
if mushroom:
hero.findNearestItem()
items = self.findNearestItem()
if hero.findItems():
item = self.findItems()
self.findItems()
if enemy == hero.findNearestEnemy():
hero.findNearestEnemy()
hero.attack(enemy)
if enemy:
hero.attack(enemy)
hero.shield()
enemy = hero.findNearestEnemy()
hero.cleave(enemy)
if enemy:
hero.attack(enemy)
if enemy:
hero.findNearestEnemy()
else:
enemy = hero.findNearestEnemy()
hero.attack(enemy)
if item == hero.findItems():
item = hero.findNearestItem()
else:
hero.findNearestEnemy()
hero.attack(enemy)
if hero.findFlag(“green”):
hero.findFlag(“green”)
hero.pickUpFlag(flag)
hero.removeFlag(flag)
mushroom = hero.findItems()
items = self.findItems()
if mushroom:
hero.findNearestItem()
items = self.findNearestItem()
if hero.findItems():
item = self.findItems()
self.findItems()

Thank you,
IcyFire

It’s too hard to read your code. Please read the FAQ with easy to follow directions on how to post it using the </> button.

https://discourse.codecombat.com/faq

Don’t copy and paste your code from here. Copy and paste it from the game or the formatting doesn’t work.

1 Like
if item == hero.findItems():
item = hero.findNearestItem()

Do you see how your code does not make sense?
item was never defined before, so this will always turn out to be false.
How did you make your way to the desert if you did not know these programming basics?!

Thank You for your opinion @SuperSmacker. I will consider this carefully and revise my code.

1 Like