# Help with Air Bridge (Python)

**URL:** <https://discourse.codecombat.com/t/help-with-air-bridge-python/13803>\
**Category:** Uncategorized\
**Created:** [February 7, 2018, 4:04am UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803 "2018-02-07T04:04:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebasluke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sebasluke/32/7181_2.png) [@sebasluke](https://discourse.codecombat.com/u/sebasluke)\
**Post date:** [February 7, 2018, 4:04am UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/1 "2018-02-07T04:04:41Z")

</div>

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

```python
# 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 = enemy.health
        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:
        hero.attack(enemy)
    

```

THANKS!

---

<div class="post-metadata">

**Author:** ![Ender\_Dragon23](https://avatars.discourse-cdn.com/v4/letter/e/d9b06d/32.png) [@Ender\_Dragon23](https://discourse.codecombat.com/u/Ender_Dragon23)\
**Post date:** [February 7, 2018, 2:03pm UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/2 "2018-02-07T14:03:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joey\_the\_rat](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/joey_the_rat/32/7477_2.png) [@Joey\_the\_rat](https://discourse.codecombat.com/u/Joey_the_rat)\
**Post date:** [February 11, 2018, 8:50pm UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/3 "2018-02-11T20:50:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gabriel\_Dupuis](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/gabriel_dupuis/32/7450_2.png) [@Gabriel\_Dupuis](https://discourse.codecombat.com/u/Gabriel_Dupuis)\
**Post date:** [February 11, 2018, 11:17pm UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/4 "2018-02-11T23:17:58Z")

</div>

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 enemy.health and not enemy.maxHealth

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

Good luck

---

<div class="post-metadata">

**Author:** ![sebasluke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sebasluke/32/7181_2.png) [@sebasluke](https://discourse.codecombat.com/u/sebasluke)\
**Post date:** [February 16, 2018, 1:30am UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/5 "2018-02-16T01:30:08Z")

</div>

You’re right!! thanks

---

<div class="post-metadata">

**Author:** ![sebasluke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sebasluke/32/7181_2.png) [@sebasluke](https://discourse.codecombat.com/u/sebasluke)\
**Post date:** [February 16, 2018, 1:30am UTC](https://discourse.codecombat.com/t/help-with-air-bridge-python/13803/6 "2018-02-16T01:30:57Z")

</div>

Thanks you’re right!!

An if enemy is not weakEnemy did the trick
