Help on level reaping fire{SOLVED}

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?

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()

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

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()

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:

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:

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.

1 Like

Can anybody plz help me?!!

I need help badly, please!!!

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.

1 Like
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()

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.

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:

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

or

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.

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().

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.

Thanks, guys, I figured it out!!!