# Siege of Stonehold \[Help Python\] \[Solved\]

**URL:** <https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291>\
**Category:** Level Help\
**Created:** [April 29, 2019, 1:14am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291 "2019-04-29T01:14:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Powerbomb323\_YT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_powerbomb323_yt/32/10109_2.png) [@\_Powerbomb323\_YT](https://discourse.codecombat.com/u/_Powerbomb323_YT)\
**Post date:** [April 29, 2019, 1:14am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/1 "2019-04-29T01:14:23Z")

</div>

This is my code. The character won’t move to the flag to pick it up.

```python
# Help your friends beat the minions that Thoktar sends against you.
# You'll need great equipment and strategy to win.
# Flags might help, but it's up to you–be creative!
# There is a doctor behind the fence. Move to the X to get healed!
flag = hero.findflag("green")
enemy = hero.findNearestEnemy()

while True:
    if flag:
        hero.pickUpFlag(flag)
    elif enemy:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        else:
            hero.attack(enemy)
        pass

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [April 29, 2019, 1:23am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/2 "2019-04-29T01:23:07Z")

</div>

Your current code just looks for the flag once at the beginning. Move the flag variable line into the while True loop and it will always be checking for a flag. You’ll want to do the same with the enemy variable, move that into the while True to make sure your hero is always looking for one.

---

<div class="post-metadata">

**Author:** ![\_Powerbomb323\_YT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_powerbomb323_yt/32/10109_2.png) [@\_Powerbomb323\_YT](https://discourse.codecombat.com/u/_Powerbomb323_YT)\
**Post date:** [April 29, 2019, 1:25am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/3 "2019-04-29T01:25:11Z")

</div>

Okay, I’ll try that really quick.

---

<div class="post-metadata">

**Author:** ![\_Powerbomb323\_YT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_powerbomb323_yt/32/10109_2.png) [@\_Powerbomb323\_YT](https://discourse.codecombat.com/u/_Powerbomb323_YT)\
**Post date:** [April 29, 2019, 1:30am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/4 "2019-04-29T01:30:30Z")

</div>

Thank you @brooksy125, for your help it worked.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [April 29, 2019, 1:32am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/5 "2019-04-29T01:32:34Z")

</div>

You are welcome! Glad to help. 🤓

---

<div class="post-metadata">

**Author:** ![boogoley\_boogoley](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/boogoley_boogoley/32/20120_2.png) [@boogoley\_boogoley](https://discourse.codecombat.com/u/boogoley_boogoley)\
**Post date:** [February 7, 2021, 7:02am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/6 "2021-02-07T07:02:01Z")

</div>

what is wrong with this code 🙄:

while True:  
flag = hero.findflag(“green”)  
enemy = hero.findNearestEnemy()  
if flag:  
hero.pickUpFlag(flag)  
elif enemy \< 11:  
if hero.isReady(“cleave”):  
hero.cleave(enemy)  
else:  
hero.shield()  
hero.attack(enemy)  
pass

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [February 7, 2021, 9:48am UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/7 "2021-02-07T09:48:04Z")

</div>

Well. First make sure hero.findFlag(“green”) has a capital F for Flag.  
Then, you have to use hero.distanceTo(enemy) \< 11, rather than just enemy \< 11. Enemy is a person, not a number. You can only use \< and \> for numbers. It doesn’t work with people.  
Also, what if the enemy is closer than 11, but you’re not ready to cleave? Maybe you should put an elif enemy inside that so that you can attack an enemy even when it’s closer than 11.  
Finally, in your else, you attack an enemy without checking it exists. Maybe you should use elif enemy again.  
Please could you put ``` on a new line before and after your code, so that I can see the spaces at the start of the line.

---

<div class="post-metadata">

**Author:** ![boogoley\_boogoley](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/boogoley_boogoley/32/20120_2.png) [@boogoley\_boogoley](https://discourse.codecombat.com/u/boogoley_boogoley)\
**Post date:** [February 8, 2021, 4:10pm UTC](https://discourse.codecombat.com/t/siege-of-stonehold-help-python-solved/18291/8 "2021-02-08T16:10:29Z")

</div>

Thanks 😇 👍 I am so happy yay

🥰 🤗
