# Help on level reaping fire{SOLVED}

**URL:** <https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775>\
**Category:** Level Help\
**Created:** [August 25, 2015, 11:49pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775 "2015-08-25T23:49:41Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![CantMelee](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@CantMelee](https://discourse.codecombat.com/u/CantMelee)\
**Post date:** [February 22, 2017, 6:52pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/21 "2017-02-22T18:52:02Z")

</div>

I tried my code, it works but the fangriders instantly override my griffins and kill them, it’s all downhill from there… Is there a problem with my code?

```python
def chooseStrategy():
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    # 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"
    elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
        return "fight-back"
        # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    for griffin in self.findByType("griffin-rider"):
        if griffin:
            enemy = griffin.findNearest(griffin.findEnemies())
            if enemy:
                self.command(griffin, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    bestRatio = 0
    bestCoin = None
    for coin in hero.findItems():
        coinRatio = coin.value / hero.distanceTo(coin)
        if coinRatio > bestRatio:
            bestRatio = coinRatio
            bestCoin = coin
            distanceCoin = hero.distanceTo(bestCoin)
            if bestCoin and hero.isReady("jump") and distanceCoin >= 10:
                hero.jumpTo(bestCoin)
                hero.move(bestCoin.pos)
            elif bestCoin:
                hero.move(bestCoin.pos)
            
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = hero.findNearest(hero.findEnemies())
    distance = hero.distanceTo(enemy)
    if enemy and distance > 30:
        hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()

```

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 22, 2018, 9:37pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/22 "2018-03-22T21:37:33Z")

</div>

I am getting a error saying that the computer cannot read type of null. Can anyone help me?

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 22, 2018, 9:38pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/23 "2018-03-22T21:38:22Z")

</div>

Here is my code:  
def chooseStrategy():  
enemies = self.findEnemies()  
enemy=self.findNearest(enemies)  
# If you can summon a griffin-rider, return “griffin-rider”  
if self.gold \>= self.costOf(“griffin-rider”):  
return “griffin-rider”  
# If there is a fangrider on your side of the mines, return “fight-back”  
if self.findByType(“fangrider”)==True:  
if self.distanceTo(self.findNearest(self.findByType(“fangrider”))) \<= 50:  
return “fight-back”  
else:  
return “collect-coins”

# Otherwise, return “collect-coins”

def commandAttack():  
# Command your griffin riders to attack ogres.  
friends=self.findFriends()  
for friend in friends:  
enemies = self.findEnemies()  
enemy = hero.findNearest(hero.findEnemies())  
if enemy.type==“munchkin”:  
self.command(friend, “attack”, self.findNearest(self.findByType(“munchkin”)))  
elif enemy.type==“ogre”:  
self.command(friend, “attack”, self.findNearest(self.findByType(“ogre”)))  
elif enemy.type==“thrower”:  
self.command(friend, “attack”, self.findNearest(self.findByType(“thrower”)))  
elif enemy.type==“scout”:  
self.command(friend, “attack”, self.findNearest(self.findByType(“scout”)))

def pickUpCoin():  
# Collect coins  
coin=self.findNearest(self.findItems())  
self.move(coin.pos)  
pass  
def heroAttack():  
# Your hero should attack fang riders that cross the minefield.  
if self.distanceTo(self.findNearest(self.findByType(“fangrider”))) \< 15:  
self.attack(self.findNearest(self.findByType(“fangrider”)))  
pass

while True:  
commandAttack()  
strategy = chooseStrategy()  
# Call a function, depending on what the current strategy is.  
if self.findFriends():  
commandAttack()  
strategy = chooseStrategy()  
# Call a function, depending on what the current strategy is.  
if strategy==“griffin-rider”:  
self.summon(“griffin-rider”)  
elif strategy==“fight-back”:  
heroAttack()  
else:  
pickUpCoin()

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 22, 2018, 10:51pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/24 "2018-03-22T22:51:29Z")

</div>

![FormatCode](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/0/03e091050fe4eed8c0076eee4ab979e171ba14c3.jpg)

To post your code properly **_from the game_** , use the **\</\>** button or it won’t format properly. When you click the **\</\>** button, the following will appear:

 ![PostCode](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/7/78430fb6ee8dec450c5a0355db89d0dc189030b4.JPG)

Please paste **ALL** of your code inside the triple back tick marks.

# ``` \<— Triple back tick marks.

**Paste ALL of your code in here.**

# ``` \<— Triple back tick marks.

There are many people here willing and able to help. If you use the **\</\>** button correctly, then **ALL** of your code should look like this:

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

```

If **ALL** of your code isn’t formatted like the code above, then you’re doing it wrong and **_we can’t see the structure of the code_** to troubleshoot whether or not that is the issue. Use the **\</\>** button and **_help us help you_**. This works when sending a private message as well.

Thank you.

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 24, 2018, 2:52am UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/25 "2018-03-24T02:52:55Z")

</div>

Can anybody plz help me?!!

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 24, 2018, 2:53am UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/26 "2018-03-24T02:53:17Z")

</div>

I need help badly, please!!!

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 24, 2018, 3:36am UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/27 "2018-03-24T03:36:01Z")

</div>

Please post your code as explained above. There are many people here willing and able to help but there is a very tiny degree of effort required on your part to enable them to do so. It’s really easy but you’re going to have to read and follow the directions above.

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 24, 2018, 5:49pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/28 "2018-03-24T17:49:56Z")

</div>

```python
def chooseStrategy():
enemies = self.findEnemies()
enemy=self.findNearest(enemies)
# If you can summon a griffin-rider, return “griffin-rider”
if self.gold >= self.costOf(“griffin-rider”):
return “griffin-rider”
# If there is a fangrider on your side of the mines, return “fight-back”
if self.findByType(“fangrider”)==True:
if self.distanceTo(self.findNearest(self.findByType(“fangrider”))) <= 50:
return “fight-back”
else:
return “collect-coins”

Otherwise, return “collect-coins”
def commandAttack():
# Command your griffin riders to attack ogres.
friends=self.findFriends()
for friend in friends:
enemies = self.findEnemies()
enemy = hero.findNearest(hero.findEnemies())
if enemy.type==“munchkin”:
self.command(friend, “attack”, self.findNearest(self.findByType(“munchkin”)))
elif enemy.type==“ogre”:
self.command(friend, “attack”, self.findNearest(self.findByType(“ogre”)))
elif enemy.type==“thrower”:
self.command(friend, “attack”, self.findNearest(self.findByType(“thrower”)))
elif enemy.type==“scout”:
self.command(friend, “attack”, self.findNearest(self.findByType(“scout”)))

def pickUpCoin():
# Collect coins
coin=self.findNearest(self.findItems())
self.move(coin.pos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
if self.distanceTo(self.findNearest(self.findByType(“fangrider”))) < 15:
self.attack(self.findNearest(self.findByType(“fangrider”)))
pass

while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if self.findFriends():
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy==“griffin-rider”:
self.summon(“griffin-rider”)
elif strategy==“fight-back”:
heroAttack()
else:
pickUpCoin()

```

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 24, 2018, 5:52pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/29 "2018-03-24T17:52:44Z")

</div>

My problem is that it cannot read type of null in the line: enemy = hero.findNearest(hero.findEnemies()) and I don’t know why this is wrong.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 24, 2018, 6:30pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/30 "2018-03-24T18:30:20Z")

</div>

From now on, please copy the code **_from the game_** , **not** from here. Once you pasted it here, the formatting is gone.

If you’re receiving a null error, it’s probably because you don’t check for an enemy before checking for enemy.type. Try:

```python
if enemy and enemy.type == "munchkin":

```

or

```python
if enemy:
    if enemy.type == "muchkin":
        self.command(friend, “attack”, self.findNearest(self.findByType(“munchkin”)))
    elif enemy.type == "ogre":

```

Either way, make sure you check for the existence of an enemy first.

Thank you for trying to post your code properly. Next time just copy it from the game, not from here.

---

<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:** [March 24, 2018, 6:35pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/31 "2018-03-24T18:35:46Z")

</div>

From what I could see, the griffin riders will only attack one enemy at a time. You don’t have to define `hero.findEnemies()` twice. You only attack the enemies who’s type is not fang-riders in what I could see. So then change the `if enemy.type == "whatever the enemy type is"` to `if enemy.type != "fangrider"`. They will only target one enemy, so change `enemy = hero.findNearest(hero.findEnemies())` to `enemy = friend.findNearestEnemy()`.

> [@MunkeyShynes](#):
>
> To post your code properly from the game, use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear:

You also said this a bunch of times in different topics.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 24, 2018, 6:47pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/32 "2018-03-24T18:47:29Z")

</div>

> [@Seojin\_Roy\_Lee](#):
>
> You also said this a bunch of times in different topics.

Wouldn’t it be great if people read directions first? It seems like I have to post this at least once a day.

---

<div class="post-metadata">

**Author:** ![Anish\_Leekkala](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Anish\_Leekkala](https://discourse.codecombat.com/u/Anish_Leekkala)\
**Post date:** [March 24, 2018, 8:23pm UTC](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775/33 "2018-03-24T20:23:44Z")

</div>

Thanks, guys, I figured it out!!!

[Previous page](https://discourse.codecombat.com/t/help-on-level-reaping-fire-solved/4775.md?page=1)
