# Forest storm help (please help i'm desperate)

**URL:** <https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287>\
**Category:** Level Help\
**Created:** [April 3, 2024, 12:32am UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287 "2024-04-03T00:32:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![meee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/meee/32/38150_2.png) [@meee](https://discourse.codecombat.com/u/meee)\
**Post date:** [April 3, 2024, 12:32am UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287/1 "2024-04-03T00:32:07Z")

</div>

I am for some reason not collecting coins

code:  
def heroAttack():  
enemy = hero.findNearestEnemy()  
if enemy:  
if hero.distanceTo(enemy) \< 15:  
if enemy.type == “munchkin”:  
hero.attack(enemy)  
return “enemy”

def heroCollect():  
item = hero.findNearestItem()  
if item:  
if hero.distanceTo(item) \< 15:  
if item == “coin”:  
hero.moveXY(item.pos)  
return “item”

while True:  
enemy = hero.findNearestEnemy()  
if enemy:  
heroAttack()  
item = hero.findNearestItem()  
if item:  
heroCollect()

---

<div class="post-metadata">

**Author:** ![Yashins](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/yashins/32/41995_2.png) [@Yashins](https://discourse.codecombat.com/u/Yashins)\
**Post date:** [April 3, 2024, 8:11am UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287/2 "2024-04-03T08:11:56Z")

</div>

Hello, @meee

Please format your code, by pressing the small menu on top, as it makes it easier to read your code, and understanding the indentation of your code.  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/8/a/8a5230bcf22a9c9d1f721e2da5128c928001c70d.png)

And welcome to the discourse! We hope you’ll enjoy the discourse here, just don’t forget to read **the FAQ’s and Rules**.  
🎊 🎊 🎊 🎊 🎊 🎊

---

<div class="post-metadata">

**Author:** ![Yashins](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/yashins/32/41995_2.png) [@Yashins](https://discourse.codecombat.com/u/Yashins)\
**Post date:** [April 3, 2024, 8:13am UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287/3 "2024-04-03T08:13:02Z")

</div>

Return is not needed in this code.

---

<div class="post-metadata">

**Author:** ![porter119](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/porter119/32/36770_2.png) [@porter119](https://discourse.codecombat.com/u/porter119)\
**Post date:** [April 3, 2024, 1:21pm UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287/4 "2024-04-03T13:21:54Z")

</div>

Try this:

```python
def heroAttack():
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.distanceTo(enemy) < 15:
            if enemy.type == "munchkin":
                hero.attack(enemy)

def heroCollect():
    item = hero.findNearestItem()
    if item:
        if hero.distanceTo(item) < 15:
            if item.type == "coin":
                hero.moveXY(item.pos.x, item.pos.y)

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        heroAttack()
    item = hero.findNearestItem()
    if item:
        heroCollect()

```

And welcome to the discourse!

---

<div class="post-metadata">

**Author:** ![meee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/meee/32/38150_2.png) [@meee](https://discourse.codecombat.com/u/meee)\
**Post date:** [April 4, 2024, 10:10pm UTC](https://discourse.codecombat.com/t/forest-storm-help-please-help-im-desperate/37287/5 "2024-04-04T22:10:35Z")

</div>

Thank you so much. I owe you my life.
