Help with Air Bridge (Python)

Hi there, I’m using this code, but the pet cannot carry it, it says, I can’t carry it… is it because the Hero has already killed it? Should I find a way for the weakest to not be killed?

Here’s my code

# Help peasants to escape.

def onSpawn(event):
    # We need to save three peasants.
    remainingPeasants = 3
    while remainingPeasants > 0:
        # Take a good position.
        pet.moveXY(40, 55)
        peasant = pet.findNearestByType("peasant")
        if peasant:
            # Carry the peasant to the center passage.
            pet.carryUnit(peasant, 40, 34)
            remainingPeasants -= 1
    # Next find a weak ogre and carry it to the fire traps:
    #define globals
    enemies = hero.findEnemies()
    enemyCount = 0
    minHealth = 9999
    weakEnemy = None
    #find weakest enemy
    while enemyCount < len(enemies):
        enemy = enemies[enemyCount]
        enemyHealth =
        if enemyHealth < minHealth:
            minHealth = enemyHealth
            weakEnemy = enemy
        enemyCount += 1
    #carry the weakest enemy
    pet.moveXY(weakEnemy.pos.x, weakEnemy.pos.y)
    pet.carryUnit(weakEnemy, 41, 17)

pet.on("spawn", onSpawn)

# Fight!
while True:
    #find enemy
    enemy = hero.findNearestEnemy()
    #if enemy, attack
    if enemy:


try adding in a munchkin = pet.findNearestByType(“munchkin”) in your code
and take out the while loop

1 Like

your if statement is wrong
set minhealth to 0
and then if enemyhealth > minhealth

ur hero is probably killing the munchkin too fast, and the next enemy which is the weakest is probably an injured ogre since you only specify and not enemy.maxHealth

Change for enemy.maxHealth and you could also specify the enemy type for “munchkin”

Good luck

1 Like

You’re right!! thanks

Thanks you’re right!!

An if enemy is not weakEnemy did the trick