# Reaping Fire Help

**URL:** <https://discourse.codecombat.com/t/reaping-fire-help/14945>\
**Category:** Uncategorized\
**Created:** [June 11, 2018, 11:45am UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945 "2018-06-11T11:45:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![awwsoclose](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@awwsoclose](https://discourse.codecombat.com/u/awwsoclose)\
**Post date:** [June 11, 2018, 11:45am UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/1 "2018-06-11T11:45:37Z")

</div>

Hello all,

In this level, my hero just stands still and does nothing. Can someone point out where I messed up? Thanks!

```python
function chooseStrategy() {
    var enemies = hero.findEnemies();
    // If you can summon a griffin-rider, return "griffin-rider"
    if(hero.gold >= hero.costOf("griffin-rider")){
      return "griffin-rider";
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
for(var i=0;i<enemies.length;i++){
    var distance = hero.distanceTo(enemy);
    var flyer= enemies[i];
     if(flyer && distance < 30 ){
    return "fight-back";
     }

    // Otherwise, return "collect-coins"
    else{
        return "collect-coins";
    }
}
}

function commandAttack() {
    // Command your griffin riders to attack ogres.
    var enemy= hero.findNearest(hero.findEnemies());
    if(enemy && enemy.type == "ogre"){
        hero.command(griffin-riders,'attack',enemy);
        }
}

function pickUpCoin() {
    // Collect coins
    var coin= hero.findNearest(hero.findItems());
    if(coin){
        hero.move(coin.pos);
        }
}

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy && enemy.type==fangriders){
        hero.attack(enemy);
        }
}

while(true) {
    commandAttack();
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"){
        commandAttack();
        }
        if(strategy == "fight-back"){
            heroAttack();
            }
            if(strategy =="collect-coins"){
                pickUpCoin();
                }
}

```

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [June 11, 2018, 3:05pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/2 "2018-06-11T15:05:52Z")

</div>

when the strategy returned “griffin-rider” you were supposed to summon one griffin-rider. You also didn’t define `griffin-riders`. And, if they were going to attack,you had to show that a commandable unit was standing there.

---

<div class="post-metadata">

**Author:** ![Archion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/archion/32/26234_2.png) [@Archion](https://discourse.codecombat.com/u/Archion)\
**Post date:** [June 11, 2018, 6:15pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/3 "2018-06-11T18:15:04Z")

</div>

@Seojin_Roy_Lee I guess you got your account back. Congrats 😄

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [June 11, 2018, 7:34pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/4 "2018-06-11T19:34:10Z")

</div>

Right (I still don’t like 20 character.)

---

<div class="post-metadata">

**Author:** ![awwsoclose](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@awwsoclose](https://discourse.codecombat.com/u/awwsoclose)\
**Post date:** [June 11, 2018, 8:50pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/5 "2018-06-11T20:50:36Z")

</div>

Thanks for replying!

I changed my code and tweaked it a bit and got this:

```python
function chooseStrategy() {
    var enemy = hero.findNearest(hero.findEnemies());
    // If you can summon a griffin-rider, return "griffin-rider"
    if(hero.gold >= hero.costOf("griffin-rider")){
      hero.summon("griffin-rider");
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
  else if(enemy){
      var distance = hero.distanceTo(enemy);
     if(enemy && distance < 10 ){
    return "fight-back";
     }
  }

    // Otherwise, return "collect-coins"
    else{
        return "collect-coins";
    }
}

function commandAttack() {
    // Command your griffin riders to attack ogres.
    var enemy= hero.findNearest(hero.findEnemies());
    var friend = hero.findByType('griffin-rider');
    if(enemy && enemy.type == "ogre"){
        hero.command(friend,'attack',enemy);
        }
}

function pickUpCoin() {
    // Collect coins
    var coin= hero.findNearest(hero.findItems());
    if(coin){
        var coinPos={'x':coin.pos.x,'y':coin.pos.y};
        hero.move(coinPos);
        }
}

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy && enemy.type=='fang-riders'){
        hero.attack(enemy);
        }
}

while(true) {
    commandAttack();
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"){
        commandAttack();
        }
      else if(strategy == "fight-back"){
            heroAttack();
            }
         else if(strategy =="collect-coins"){
                pickUpCoin();
                }
}

```

This time my hero moves and picks up coins, summons 1 griffin rider, and stops moving when an enemy comes

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [June 11, 2018, 9:06pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/6 "2018-06-11T21:06:01Z")

</div>

You have some weird indentations going on. The error is probably because of the indentations.

Also how come you have the commandAttack(); before the strategy variable, outside the if loops?

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [June 11, 2018, 9:21pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/7 "2018-06-11T21:21:06Z")

</div>

I was going to say that…

---

<div class="post-metadata">

**Author:** ![awwsoclose](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@awwsoclose](https://discourse.codecombat.com/u/awwsoclose)\
**Post date:** [June 11, 2018, 9:25pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/8 "2018-06-11T21:25:38Z")

</div>

good question lol. it was already there, and i guess i forgot to delete it. as for the weird indentations, when I hit “enter” that’s where the curser went to i guess. I"ll try to fix everything =]

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [June 11, 2018, 9:27pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/9 "2018-06-11T21:27:26Z")

</div>

multiple times, when I was about to finish a post, I accidentally deleted the whole thing, so then I either gave up or I wrote the whole thing again.

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [June 11, 2018, 10:26pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/10 "2018-06-11T22:26:37Z")

</div>

Will check new code …  
In first code you did’t summon griffin riders. In second you don’t have ‘griffin-rider’ strategy.

---

<div class="post-metadata">

**Author:** ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)\
**Post date:** [June 13, 2018, 2:21pm UTC](https://discourse.codecombat.com/t/reaping-fire-help/14945/11 "2018-06-13T14:21:13Z")

</div>

> [@xython](#):
>
> did’t

needs to be edited the 3rd time, spelling error.
