# \[solved\]Siege of stonehold (plz help)

**URL:** <https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352>\
**Category:** Level Help\
**Created:** [November 12, 2020, 6:16pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352 "2020-11-12T18:16:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [November 12, 2020, 6:16pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/1 "2020-11-12T18:16:33Z")

</div>

I don’t know why it’s not working

```python
while (true) {
    var flag = this.findFlag();
    var enemy = this.findNearestEnemy();
    if (flag) {
        this.pickUpFlag(flag);
    } else {
        hero.shield();
    }
    if (enemy) {
        if (this.distanceTo(enemy) < 50) {
            if (this.isReady("cleave")) {
                this.cleave(enemy);
            } else {
                this.attack(enemy);
            }
        }
    }
}

```

it is in JavaScript

---

<div class="post-metadata">

**Author:** ![cheddarcheese](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cheddarcheese/32/22417_2.png) [@cheddarcheese](https://discourse.codecombat.com/u/cheddarcheese)\
**Post date:** [November 12, 2020, 6:20pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/2 "2020-11-12T18:20:57Z")

</div>

id recomend going to the wizard to heal but if you have over 1500 health then you dont need to

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [November 12, 2020, 6:25pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/3 "2020-11-12T18:25:54Z")

</div>

![Screenshot (18)](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/1/a1207f9dc8ad89b21e7ba12dc074261dc94f1076.png)  
it also won’t let me attack the boss

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 12, 2020, 6:29pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/4 "2020-11-12T18:29:49Z")

</div>

you don’t need to attack thokar

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [November 12, 2020, 6:46pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/5 "2020-11-12T18:46:43Z")

</div>

That helps a lot I thought you had to defeat him; because of the mission tab  
I’ll try that

---

<div class="post-metadata">

**Author:** ![Code\_Master](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/code_master/32/16184_2.png) [@Code\_Master](https://discourse.codecombat.com/u/Code_Master)\
**Post date:** [November 12, 2020, 7:09pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/6 "2020-11-12T19:09:29Z")

</div>

Try to delete the

```python
      else {
        hero.shield();
    }

```

And change

```python
    if (flag) {
        this.pickUpFlag(flag);
    } 
    if (enemy) {
        if (this.distanceTo(enemy) < 50) {
            if (this.isReady("cleave")) {
                this.cleave(enemy);
            } else {
                this.attack(enemy);
            }
        }
    }

```

into

```python
    if (flag) {
        this.pickUpFlag(flag);
    } else if (enemy) {
        if (this.distanceTo(enemy) < 50) {
            if (this.isReady("cleave")) {
                this.cleave(enemy);
            } else {
                this.attack(enemy);
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [November 12, 2020, 7:19pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/7 "2020-11-12T19:19:20Z")

</div>

Thank you! (20crcter)  
I was so close then this: ![Screenshot (19)](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/7/b/7b8ac07252ebbdf2525843a8b8c0e6d151e2c72a.png)  
Sorry if its small

---

<div class="post-metadata">

**Author:** ![Code\_Master](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/code_master/32/16184_2.png) [@Code\_Master](https://discourse.codecombat.com/u/Code_Master)\
**Post date:** [November 12, 2020, 7:19pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/8 "2020-11-12T19:19:33Z")

</div>

You are welcome! Glad to help!

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [November 12, 2020, 7:53pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/9 "2020-11-12T19:53:28Z")

</div>

I was typing new code because i had 4 health left and I somehow managed to win

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [November 13, 2020, 7:53am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-plz-help/25352/10 "2020-11-13T07:53:53Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
