Reaping Fire coding errror?


#1

When I run my code, my hero continually tries to summon Griffin Riders, and, as you can imagine, stalls in place for a long time, which causes me to lose the level. Here is my code:

def chooseStrategy():
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if self.gold > self.costOf("griffin-rider"):
        return "griffin-rider"
    # If you can summon a griffin-rider, return "griffin-rider"
    elif enemy:
        if enemy.type is "fangrider" and self.distanceTo(enemy) < 30:
            return "fight-back"
    # If there is a fangrider on your side of the mines, return "fight-back"
    else:
        return "collect-coins"
    # Otherwise, return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    for griffin in self.findByType("griffin-rider"):
        if griffin:
            enemy = griffin.findNearestEnemy()
            if enemy:
                self.command(griffin, "attack", enemy)
    
def pickUpCoin():
    # Collect coins
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = self.findNearest(self.findEnemies())
    if enemy and self.distanceTo(enemy) < 30:
        self.attack(enemy)
loop:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy = "griffin-rider":
        self.summon("griffin-rider")
    if strategy = "fight-back":
        heroAttack()
    if strategy = "collect-coins":
        pickUpCoin()

What am I doing wrong?


#2

Comparison operator is == and not =.


#4

Question, I cant attack without my sword but, I cant summon without my hammer
what do?


#5

You mean you can’t summon without a hammer equipped?


#6

facepalm, I didn’t know you don’t need the hammer to summon


#7

i can’t believe i missed this, i have literally nearly the same code and ran into the same problem.

such a simple thing to fix and yet i have looked over it for hours.