Summits Gate Warlock reviving friends issue

In Summit’s Gate. I get to the Warlocks which I’m trying to kill with my Griffins.
I do a findFriends to get an array of my Griffins to loop through to attack the Warlocks.
I think what is happening is that one of my griffins is being killed, then resurrected on the warlock side and so when I try and command it to attack the Warlocks an error is thrown (in commandGriffin function)

Does anyone have any ideas about this please?

In the screenshot below Christofide is one of my griffin-riders

Here is my code

 #Commented out to stop infinite loop.
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
# You need 2 archers and 2 soldiers.
def att(enemy):
    if enemy.type!='door':
        if enemy and hero.distanceTo(enemy)>5 and hero.isReady("jump") and enemy.type!='tower':
            hero.jumpTo(enemy.pos)
        elif enemy and enemy.health>10 and hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
            if hero.isReady("shield"):
                hero.shield()
        elif enemy and hero.isReady("cleave") and hero.distanceTo(enemy)<5:
            hero.cleave(enemy)
            if hero.isReady("shield"):
                hero.shield()
        elif enemy and hero.isReady("bash") and hero.distanceTo(enemy)<3:
            hero.bash(enemy)
            if hero.isReady("shield"):
                hero.shield()
        elif enemy:
            hero.attack(enemy)
        elif enemy and hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
            if hero.isReady("shield"):
                hero.shield()
                
            
# This function can be helpful.
def summonAndSend(type, x, y):
    while hero.gold>hero.costOf(type):
        hero.summon(type)
        unit = hero.built[len(hero.built)-1]
        hero.command(unit, "move", {"x": x, "y": y})

# Find the paladin with the lowest health.
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findByType("paladin", hero.findFriends())
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend

def commandPaladin():
    # Heal the paladin with the lowest health using lowestHealthPaladin()
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    # And don't forget, they can attack, too!
    paladins=hero.findByType("paladin", hero.findFriends())
    for paladin in paladins:
        if paladin.canCast("heal"):
            needhealing=lowestHealthPaladin()
            if hero.health<hero.maxHealth and hero.distanceTo(paladin)<15:
                hero.command(paladin, "cast", "heal", hero)
            elif needhealing:
                #hero.say('Paladin healing: '+needhealing)
                hero.command(paladin, "cast", "heal", needhealing)
        enemy=paladin.findNearestEnemy()
        if enemy and enemy.type!='door':
            #hero.say('Paladin should be attacking: '+enemy)
            hero.command(paladin, "attack",enemy)
            #hero.command(paladin, "shield")
        elif paladin.health<200:
            hero.command(paladin, "shield")
        pass

def commandSoldier():
    soldiers=hero.findByType('soldier',hero.findFriends())
    for soldier in soldiers:
        enemy = soldier.findNearestEnemy()
        if enemy and enemy.type!='door':
            hero.command(soldier, "attack", enemy)

def commandGriffin(warlocks):
    griffins=hero.findByType("griffin-rider", hero.findFriends())
    hero.say('number of griffins '+len(griffins))
    hero.say('number of warlock '+len(warlocks))
    for griffin in griffins:
        if len(warlocks)==0:
            enemies=hero.findEnemies()
        else:
            enemies=warlocks
            
        for enemy in enemies:
            if enemy.type=='warlock':
                hero.command(griffin, "attack", enemy)
                break
            else:
                enemy=griffin.findNearestEnemy()
                if enemy and enemy.type!='door':
                    hero.command(griffin, "attack", enemy)
                    break
        

def commandArcher():
    archers=hero.findByType('archer',hero.findFriends())
    for archer in archers:
        enemy=archer.findNearestEnemy()
        if enemy and enemy.type!='door':
            hero.command(archer, "attack", enemy)

def commandPeasant(friend):
    coins=friend.findItems()
    coin=friend.findNearestItem()
    hero.command(friend, "move", coin.pos)

def commandFriends(warlocks):
    # Command your friends.
    commandGriffin(warlocks)
    commandArcher()
    commandSoldier()
    commandPaladin()
  
def commandFriendsMoveTo(targetLoc):
    friends=hero.findFriends()
    for friend in friends:
        #hero.say('Move: '+friend)
        hero.command(friend, "move", targetLoc)
        
def commandTypeMoveTo(targetLoc,ftype):
    friends=hero.findByType(ftype, hero.findFriends())
    for friend in friends:
        #hero.say('Move: '+friend)
        hero.command(friend, "move", targetLoc)

def killByType(enemyType):
    enemies=hero.findByType(enemyType, hero.findEnemies())  
    for enemy in enemies:
        while enemy.health>0:
            att(enemy)
            
def getNearestByType(enemyType):
    enemies=hero.findByType(enemyType, hero.findEnemies()) 
    nearest=None
    nearDist=9999
    for enemy in enemies:
        dist=hero.distanceTo(enemy)
        if dist<nearDist:
            nearDist=dist
            nearest=enemy
    return nearest
        
            
def palsHealHero():
    #hero.say('about to be healed')
    paladins=hero.findByType('paladin', hero.findFriends()) 
    if len(paladins)<2 and hero.gold>hero.costOf('paladin'):
        #hero.say('summoning paladin')
        hero.summon('paladin')
    paladins=hero.findByType('paladin', hero.findFriends()) 
    counter=0
    while hero.health<hero.maxHealth and len(paladins)>0 :
        hero.say('palshealhero inside while')
        paladins=hero.findByType('paladin', hero.findFriends())
        for paladin in paladins:
            #hero.say('summoning paladin inside for')
            healthLev=hero.health
            if hero.health<hero.maxHealth and paladin.canCast("heal") and hero.distanceTo(paladin)<15:
                #hero.say('being healed'+counter)
                hero.command(paladin, "cast", "heal", hero)
                counter+=1
            elif hero.health<hero.maxHealth and paladin.canCast("heal") and hero.distanceTo(paladin)>=15:
                hero.command(paladin, "move", hero.pos)

def everyoneAttackSkeletons():
    #except paladins and griffin-riders
    allies=hero.findFriends()
    for ally in allies:
        enemy=ally.findNearestEnemy()
        if enemy and ally.type!='griffin-rider' and ally.type!='paladin' and enemy.type=='skeleton':
            hero.command(ally, "attack", target)



warlocks=hero.findByType("warlock", hero.findEnemies())
ftype='griffin-rider'     
commandFriendsMoveTo({"x":3,"y":40})
killByType("catapult")
killByType("scout")
killByType("munchkin")
hero.say('about to move killed all sect1')
commandFriendsMoveTo({"x":67,"y":40})
hero.say('moved friends')
hero.moveXY(92, 36)

paladins=hero.findByType("paladin", hero.findFriends())
palsHealHero()
summonAndSend('griffin-rider', 67, 40)

commandFriendsMoveTo({"x":50,"y":37})

#going to breakdown nearest door
door=getNearestByType('door')
while door.health>0:
    hero.attack(door)

hero.moveXY(60, 33)
killByType("thrower")
killByType("munchkin")

palsHealHero()
summonAndSend('griffin-rider', 50, 40)

commandFriendsMoveTo({"x":50,"y":37})

#Kill towers
hero.moveXY(124, 4)
enemies=hero.findByType("tower")
while enemies[0].health>0:
    att(enemies[0])

#get healed
commandFriendsMoveTo({"x":90,"y":37})
hero.moveXY(93,35)
palsHealHero()
summonAndSend('griffin-rider', 90, 40)

#kill other tower
hero.moveXY(122, 64)
enemies=hero.findByType("tower")
while enemies[0].health>0:
    att(enemies[0])

commandFriendsMoveTo({"x":127,"y":34})
hero.moveXY(136,35)
palsHealHero()
summonAndSend('griffin-rider', 127, 40)

#going to breakdown nearest door 2
door=getNearestByType('door')
while door.health>0:
    hero.attack(door)
    
    
#Lure Ogres out
commandFriendsMoveTo({"x":127,"y":34})
hero.moveXY(167, 35)
killByType("ogre")
hero.moveXY(167, 35)
killByType("ogre")


commandFriendsMoveTo({"x":219,"y":15}) 
palsHealHero()
summonAndSend('griffin-rider', 219, 15)


#Draw out warlocks
while hero.pos.x<273:
    hero.move({"x":277,"y":34})
hero.say('where the warlocks are')
warlocks=hero.findByType("warlock", hero.findEnemies())
#run away
while hero.pos.x>230:
    hero.move({"x":228,"y":15})
    
    
#Hopefully kill warlocks with griffins and everything else with hero and others
commandFriendsMoveTo({"x":246,"y":25})
hero.say("about to send griffs after walocks")
commandGriffin(warlocks)

warlocks=hero.findByType("warlock", hero.findEnemies())
while len(warlocks)>0:
    summonAndSend('griffin-rider', hero.pos.x, hero.pos.y)
    commandFriends(warlocks)
    enemy=hero.findNearestEnemy()
    if enemy:
        att(enemy)
    warlocks=hero.findByType("warlock", hero.findEnemies())


hero.say('clean up skeletons')
skeletons=hero.findByType("skeleton", hero.findEnemies())
while len(skeletons)>0:
    commandFriends(warlocks)
    enemy=hero.findNearestEnemy()
    if enemy:
        att(enemy)
    skeletons=hero.findByType("skeleton", hero.findEnemies())

commandFriendsMoveTo({"x":267,"y":34})

hero.say('finished skeletons get jewels')
jewels=hero.findItems()
while len(jewels)>0:
    jewel=hero.findNearestItem()
    hero.move(jewel.pos)
    jewels=hero.findItems()


hero.say('got jewels kill boss')

#going to breakdown final door
door=getNearestByType('door')
while door.health>0:
    hero.attack(door)

Hello! I’m afraid this topic will be closed because you have already made another topic about Summit’s Gate. Making 2 topics won’t make help faster.
You can tell about this issue in

your topic that was made before and people will be glad to help.

About the level:
I think you have an error because warlocks first killed your griffin-rider and then revived it and started commanding it.
Try to write if enemy.type == "warlock" and griffin.team == "humans":, instead of that if.
Good luck in the level!

3 Likes

I’m not trying to make it quicker the 2 topics are regarding different issues.

One is about how to debug an infinite loop and one is regarding looping through an array of ‘friends’ when one of them has been converted into an enemy.

To close down my posts because they happen to be on the same stage doesn’t make sense.

I’m not expecting one post to get me to the end of the stage.

I don’t understand why you have decided that one of them should be shut down.

when I’m picking griffins I’m already choosing only friendly ones by.

griffins=hero.findByType(“griffin-rider”, hero.findFriends())

using the hero.findFriends() unit parameter so I’m not sure why checking the griffin is on the human side will help as it should already be on the human side.

One tip that I have: You cannot kill warlocks no matter how hard you try

1 Like

That’s going to make the whole finishing the level a bit tricky

Thats not true, you can kill them.

1 Like

Well, in most of the levels with warlocks, you dont need to kill them

2 Likes

Yes, but you are able to kill them.

1 Like

Lets discuss this in PMs.

btw u coild add if hero.team==friend.team

2 Likes

I think in this level you have to kill them to complete the level with all rewards. I think the best strategy for killing warlocks is to overwhelm them with griffin riders as the attack from a distance with quite high damage. On this level by the time I get to the warlocks I have been summoning quite a lot of griffin riders so that will hopefully be enough