# Help! rich forager

**URL:** <https://discourse.codecombat.com/t/help-rich-forager/1907>\
**Category:** Uncategorized\
**Created:** [December 15, 2014, 10:40am UTC](https://discourse.codecombat.com/t/help-rich-forager/1907 "2014-12-15T10:40:01Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![gomersawsome](https://avatars.discourse-cdn.com/v4/letter/g/f17d59/32.png) [@gomersawsome](https://discourse.codecombat.com/u/gomersawsome)\
**Post date:** [May 28, 2015, 10:51pm UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/21 "2015-05-28T22:51:51Z")

</div>

i’m having trouble my code is

if flag:  
# What happens when I find a flag?  
self.pickUpFlag(flag)  
elif enemy:  
# What happens when I find an enemy?  
if self.isReady(“cleave”) and self.distanceTo(enemy) \<5:  
self.cleave(enemy)  
elif:  
self.attack(enemy)  
elif item:  
# What happens when I find an item?  
pos = item.pos  
x = pos.x  
y = pos.y

i cant figure out how to fix it

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [May 28, 2015, 10:54pm UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/22 "2015-05-28T22:54:26Z")

</div>

Please read the FAQ and then edit your post to correctly use ``` to format your code. (Make sure everything is indented properly.)

What is the problem? (What is it doing that you didn’t expect? error messages? etc)

---

<div class="post-metadata">

**Author:** ![gomersawsome](https://avatars.discourse-cdn.com/v4/letter/g/f17d59/32.png) [@gomersawsome](https://discourse.codecombat.com/u/gomersawsome)\
**Post date:** [May 28, 2015, 11:41pm UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/23 "2015-05-28T23:41:06Z")

</div>

sorry i worked on it and now its starting to work i just need more health

---

<div class="post-metadata">

**Author:** ![Jaydon\_Tillitson](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@Jaydon\_Tillitson](https://discourse.codecombat.com/u/Jaydon_Tillitson)\
**Post date:** [March 17, 2016, 2:44pm UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/24 "2016-03-17T14:44:32Z")

</div>

this.pickUpFlag(flag);  
}  
else if (enemy) {  
// What happens when I find an enemy?  
this.attack(enemy);  
this.attack(enemy);  
}  
else if (item) {  
// What happens when I find an item?  
var fx = pos.x;  
var fy = pos.y;  
this.moveXY(pos.x, pos.y);  
}  
}

i need help on rich forager

---

<div class="post-metadata">

**Author:** ![Jaydon\_Tillitson](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@Jaydon\_Tillitson](https://discourse.codecombat.com/u/Jaydon_Tillitson)\
**Post date:** [March 21, 2016, 1:54pm UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/25 "2016-03-21T13:54:59Z")

</div>

> [@creativejiwon](#):
>
> if (flag) {  
> // What happens when I find a flag?  
> this.pickUpFlag(flag);  
> }  
> else if (enemy) {  
> // What happens when I find an enemy?  
> this.attack(enemy);  
> this.attack(enemy);  
> }  
> else if (item) {  
> // What happens when I find an item?  
> var posi = pos.item;  
> var fx = pos.x;  
> var fy = pos.y;  
> this.moveXY(fx, fy);  
> }
> 
> }

ny body help me im confused

---

<div class="post-metadata">

**Author:** ![Flynn\_Gerard\_Trinida](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@Flynn\_Gerard\_Trinida](https://discourse.codecombat.com/u/Flynn_Gerard_Trinida)\
**Post date:** [November 8, 2016, 4:44am UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/26 "2016-11-08T04:44:41Z")

</div>

Pls help. IDK how to fix this. My code is below: (Javascript)

```python

// Use "if" and "else if" to handle any situation.
// Put it all together to defeat enemies and pick up coins!
// Make sure you bought great armor from the item shop! 400 health recommended.
while (true) {
    var flag = hero.findFlag();
    var enemy = hero.findNearestEnemy();
    var item = hero.findNearestItem();
    if (flag) {
        // What happens when I find a flag?
        hero.pickUpFlag(a); // <-- The "a"
    } else if (enemy) {
        // What happens when I find an enemy?
        while (true) { // Do I need the while-true loop?
            hero.attack(enemy);
        }
    } else if (item) {
        // What happens when I find an item?
        var posItem = pos.item;
        var fx = posItem.x;
        var fy = posItem.y;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Flynn\_Gerard\_Trinida](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@Flynn\_Gerard\_Trinida](https://discourse.codecombat.com/u/Flynn_Gerard_Trinida)\
**Post date:** [November 8, 2016, 4:47am UTC](https://discourse.codecombat.com/t/help-rich-forager/1907/27 "2016-11-08T04:47:26Z")

</div>

I found the “a” in line 10 in the code but I fixed it and it still didn’t work. PLZ HELP ME

[Previous page](https://discourse.codecombat.com/t/help-rich-forager/1907.md?page=1)
