Error in Cavern Survival pls help

even though i have the ring of skeletons it is giving me an error that “team humans cant command team
ogres”
this is my code can somebody help me pls?

def buildArmy():
    
    # Your hero can summon and command allied troops.
    
    buildOrder = ["paladin"]
    type = buildOrder[len(self.built) % len(buildOrder)]
    if self.gold >= self.costOf(type):
        self.summon(type)
carter= ({"x": 94, "y": 35})
def friendGetCoin():
    friends = self.findFriends()
    for friend in friends:
        if friend.type is "peasant":
            nearest = friend.findNearest(friend.findItems())
            if nearest:
                self.command(friend, "move", nearest.pos)
                
                
                
def onSpawn(e):
    while True:
        enemy = pet.findNearestByType("munchkin")
        # Find and fetch a "potion":
        pet.trick()
        # Find and fetch a "potion":
        pet.say("Master you are the best!!")
        pet.moveXY(hero.pos.x, hero.pos.y)
    pet.on("spawn", onSpawn)
hero.moveXY(111, 35)
hero.cast("summon-burl")
hero.resetCooldown("summon-burl")
hero.cast("summon-burl")
hero.cast("summon-undead")
hero.manaBlast()
hero.move(carter)
loop:
    friendGetCoin()
    buildArmy()
    paladin = pet.findNearestByType("paladin")
    friends = self.findFriends()
    friend = hero.findNearest(hero.findFriends())
    enemy = self.findNearest(self.findEnemies())
    if enemy:
        hero.attack(enemy)
        if hero.isReady("mana-blast") and hero.distanceTo(enemy)<11:
            hero.manaBlast()
        if hero.isReady("chain-lightning"):
            hero.cast("chain-lightning", enemy)
        if hero.health<501 and hero.distanceTo(enemy)<=21 and hero.isReady("drain-life") and enemy.health> 0:
            hero.cast("drain-life", enemy)
        if hero.isReady("poison-cloud") and hero.distanceTo(enemy)<11:
            hero.cast("poison-cloud", enemy)
        if hero.isReady("fear") and hero.distanceTo(enemy)<11:
            hero.cast("fear", enemy)
        if hero.isReady("raise-dead"):
            hero.cast("raise-dead")
            
        if friend:
            for friend in friends:
                if friend.type is "griffin-rider" or friend.type is "skeleton":
                    target = friend.findNearest(friend.findEnemies())
                    if target:
                        self.command(friend, "defend", self)
                if friend.type is "paladin" :
                    target = friend.findNearest(friend.findEnemies())
                    if enemy:
                        self.command(friend, "defend", self)
                    if hero.health < 400:
                        hero.command(paladin, "cast", "heal", hero)
    if self.isReady("summon-burl"):
        self.cast("summon-burl")
    if self.isReady("reset-cooldown"):
        self.resetCooldown("summon-burl")
    if self.isReady("summon-undead"):
        hero.cast("summon-undead")
        

I hate this error it happens to me a lot, what I normally do is say: if friend.team == "humans": that is an actual thing that you can do without an error which is quite helpful, I think that will help but sometimes that error can be extremely difficult to get rid off. :roll_eyes: I hope that works. ( I would try it but I don’t have paladins and It would be quite hard to just get rid of the bits which use paladins. sorry

Even with that, I die because it says that I can’t command team ogre (or human), and it bugs me. A lot.

If the ogre team use reanimate, and you had some units before, those units are probably still in your array but you can’t control them since they switched side.

Deadpool way of solving is good
but I guess it would be nice to use some errorHandler in that case

try:
    hero.command(unit, "action", target)
except(RuntimeError, TypeError, NameError): # or whatever the error is, if you can find it
    pass

I did not try it and I am not sure it works on codecombat but would be nice if it works

Ok I will try. Thanks! :smile: