# \[SOLVED\] Siege of Stonehold Help!

**URL:** <https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767>\
**Category:** Level Help\
**Created:** [December 12, 2014, 1:03am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767 "2014-12-12T01:03:54Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![danut](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@danut](https://discourse.codecombat.com/u/danut)\
**Post date:** [December 21, 2014, 11:29am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/21 "2014-12-21T11:29:01Z")

</div>

YOU MUST TAKE THE HAMMER AND HAVE MINIMUM 300 HEALTH  
javascript

this.buildXY(“fire-trap”, 20,52);  
this.buildXY(“fire-trap”, 22,52);  
this.buildXY(“fire-trap”, 22,56);  
this.moveXY(39, 83);  
this.buildXY(“fire-trap”, 18, 88);  
this.buildXY(“fire-trap”, 20, 84);  
this.buildXY(“fire-trap”, 21, 82);

this.buildXY(“fire-trap”, 32, 72);  
this.buildXY(“fire-trap”, 32, 68);  
this.buildXY(“fire-trap”, 32,64);

this.buildXY(“fire-trap”, 28, 72);  
this.buildXY(“fire-trap”, 28, 68);  
this.buildXY(“fire-trap”, 28,64);

this.buildXY(“fire-trap”, 24, 72);  
this.buildXY(“fire-trap”, 24, 68);  
this.buildXY(“fire-trap”, 24,64);

this.buildXY(“fire-trap”, 20, 72);  
this.buildXY(“fire-trap”, 20, 68);  
this.buildXY(“fire-trap”, 20,64);

this.moveXY(1, 67);  
this.moveXY(2, 67);  
loop {  
this.shield();

}  
//it works great

---

<div class="post-metadata">

**Author:** ![abducktion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/abducktion/32/1814_2.png) [@abducktion](https://discourse.codecombat.com/u/abducktion)\
**Post date:** [December 22, 2014, 9:13pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/22 "2014-12-22T21:13:34Z")

</div>

I need help on this level, if anybody can. I’ve already tried the fire trap approach, but first off, I can’t get it to work, and second, I don’t think that’s the right way to go about doing this.  
I’m trying to make Tharin go for the enemies if they are a certain distance away, but when I try to use this:  
var enemy = this.findNearestEnemy();  
var distance = this.distanceTo(enemy);  
if (distance \< 11) {  
this.cleave(enemy)  
It doesn’t work. It says: Find the distance to a target unit, and I’m not sure what that means. Also, can anybody help me so that I only use cleave if it is ready, otherwise I attack? I’ve tried using the this.isReady(“cleave”), but I’m not sure where to put it in my if function. Should I put it in the parenthesis (where I have distance \< 11 right now), or should I put it somewhere else? Can anybody help me? Thanks.

---

<div class="post-metadata">

**Author:** ![abducktion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/abducktion/32/1814_2.png) [@abducktion](https://discourse.codecombat.com/u/abducktion)\
**Post date:** [December 23, 2014, 2:43am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/23 "2014-12-23T02:43:18Z")

</div>

Hm… Okay, then. I managed to beat the level with the fire traps, and I think I survived with full health, too. However, I would still like to know another more… subtle way, I guess, of doing this level. But anyhow, WOOHOO!! I made it to the desert!!!

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [December 30, 2014, 4:35am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/24 "2014-12-30T04:35:11Z")

</div>

Well I use ninja (the first ranged char [not mage])  
and I use the lightning stick I move to the entrance of the “fort” and shoot every-thing  
since the lightning stick is a one shot KO it should be pretty easy but you need 300+ health to take down the last orge

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [December 31, 2014, 1:31am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/25 "2014-12-31T01:31:10Z")

</div>

I just added a better error message for that one, @abducktion: basically, you’re trying to check the distance to an enemy, but you can’t see an enemy, so you get an error. Put an `if (enemy)` check around anything that tries to find `distanceTo(enemy)`.

Lightning stick surely makes this level pretty easy, but it’s quite expensive!

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [December 31, 2014, 4:38am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/26 "2014-12-31T04:38:55Z")

</div>

Well I am a subscriber so its not that much

---

<div class="post-metadata">

**Author:** ![Andrew\_Boylan](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Andrew\_Boylan](https://discourse.codecombat.com/u/Andrew_Boylan)\
**Post date:** [January 3, 2015, 5:36am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/27 "2015-01-03T05:36:30Z")

</div>

> [@Beachkid](#):
>
> Move your character with a green flag into the upper left hand corner, and then when the ogres come, he cleaves, and kills them. Then move your character into the upper right hand corner and he does the same thing. Then move him in with the villagers, and make him try to get a flag on the other side of the wall, so he will be stuck. Then once all your allies are dead, move the flag onto the field, and clear out the remaining enemies. Best of luck!

Thank you ! Used your instructions with this javascript code :

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

```

---

<div class="post-metadata">

**Author:** ![shoodong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shoodong/32/2361_2.png) [@shoodong](https://discourse.codecombat.com/u/shoodong)\
**Post date:** [January 27, 2015, 4:18am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/28 "2015-01-27T04:18:38Z")

</div>

You must have 800+ health and do the following:

```python
loop {
    var enemies = this.findEnemies();
    var friends = this.findFriends();
    for(var i = 0; i < enemies.length; ++i) {
        var enemy = enemies[i];
        if (enemy) {
            this.attack(enemy);
        }
var friend = friends[i];
    if(friend && friend.type == "archer" && friend.type == "soldier") {
    var fx = friend.pos.x; 
    var fy = friend.pos.y;
    this.move(fx,fy);
}   
}
}

```

---

<div class="post-metadata">

**Author:** ![shoodong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shoodong/32/2361_2.png) [@shoodong](https://discourse.codecombat.com/u/shoodong)\
**Post date:** [January 27, 2015, 4:49am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/29 "2015-01-27T04:49:09Z")

</div>

Tell us how and how you did it @shoodong

---

<div class="post-metadata">

**Author:** ![shoodong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shoodong/32/2361_2.png) [@shoodong](https://discourse.codecombat.com/u/shoodong)\
**Post date:** [January 27, 2015, 4:49am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/30 "2015-01-27T04:49:51Z")

</div>

Tell us how to do it, or they will suffer

---

<div class="post-metadata">

**Author:** ![shoodong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shoodong/32/2361_2.png) [@shoodong](https://discourse.codecombat.com/u/shoodong)\
**Post date:** [January 27, 2015, 4:50am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/31 "2015-01-27T04:50:29Z")

</div>

I am not a sub and i beat it with 853 health

---

<div class="post-metadata">

**Author:** ![shoodong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shoodong/32/2361_2.png) [@shoodong](https://discourse.codecombat.com/u/shoodong)\
**Post date:** [January 27, 2015, 4:51am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/32 "2015-01-27T04:51:46Z")

</div>

Your code needs to have this

```python
if(enemy && this.distanceTo(enemy) < 10) {
    // Your code here
}

```

---

<div class="post-metadata">

**Author:** ![Rytrik](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@Rytrik](https://discourse.codecombat.com/u/Rytrik)\
**Post date:** [January 31, 2015, 10:20pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/33 "2015-01-31T22:20:50Z")

</div>

Or you can go in with sub 300 health, and plant mines with flags, and move around with flags 😛 You don’t need 800 hp for this level, cept if you’re using a “Let’s go attack everything” plan

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [February 1, 2015, 4:10am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/34 "2015-02-01T04:10:53Z")

</div>

I used a “Let’s go attack everything” so yeah

---

<div class="post-metadata">

**Author:** ![Asoccer02](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Asoccer02](https://discourse.codecombat.com/u/Asoccer02)\
**Post date:** [February 11, 2016, 8:14am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/35 "2016-02-11T08:14:12Z")

</div>

![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a300907fa92a9b64ab9db604f1732bef6e5b55fa.png)  
what is wrong with my code I don’t know what it is

---

<div class="post-metadata">

**Author:** ![Hinkle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hinkle/32/3967_2.png) [@Hinkle](https://discourse.codecombat.com/u/Hinkle)\
**Post date:** [February 11, 2016, 8:58am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/36 "2016-02-11T08:58:09Z")

</div>

The error message says variable declaration.  
You are declaring a variable in the middle of an `if` statement. You can’t do that.

You code should read:

```python
distance = self.distanceTo(enemy)
if distance < 10:
    do stuff

```

---

<div class="post-metadata">

**Author:** ![Asoccer02](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Asoccer02](https://discourse.codecombat.com/u/Asoccer02)\
**Post date:** [February 11, 2016, 9:27am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/37 "2016-02-11T09:27:19Z")

</div>

thankyou but the message still says there is something wrong with the code  
 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/e/e0eb7f11eaa22d47b2110885781aa84147ce9c11.png)

---

<div class="post-metadata">

**Author:** ![Hinkle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hinkle/32/3967_2.png) [@Hinkle](https://discourse.codecombat.com/u/Hinkle)\
**Post date:** [February 11, 2016, 9:49am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/38 "2016-02-11T09:49:07Z")

</div>

Read the error message. What does it say? The big red boxes usually give you clues as to what is wrong.

This error message means that you are trying to put null (nothing) into the `distanceTo()` method. If there is not an enemy you don’t want to find the distance to it.

---

<div class="post-metadata">

**Author:** ![Nicole\_Deni](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nicole_deni/32/6446_2.png) [@Nicole\_Deni](https://discourse.codecombat.com/u/Nicole_Deni)\
**Post date:** [June 17, 2017, 1:13am UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/39 "2017-06-17T01:13:44Z")

</div>

THANK YOU SOOOO MUCH, I DEFETED THIS LEVEL SO EASY!!! THANK YOU!!!

Nicole… 😃 😄 😉 ❤ ❤ ❤

---

<div class="post-metadata">

**Author:** ![PokasLittleOne](https://avatars.discourse-cdn.com/v4/letter/p/5fc32e/32.png) [@PokasLittleOne](https://discourse.codecombat.com/u/PokasLittleOne)\
**Post date:** [November 4, 2017, 9:27pm UTC](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767/40 "2017-11-04T21:27:20Z")

</div>

I just moved where the enemy was and barely attacked them, the peasants did pretty much all of the work…  
From the way you guys were describing it I thought that it would be really hard, but I only got hit once or twice…  
Unless it was made easier by the time I did it, that could be it to…  
also my code was ( I use javascript )  
while(true) {  
var flag = hero.findFlag();  
var enemy = hero.findNearestEnemy();  
if(flag) {  
var flagPos = flag.pos;  
var flagX = flag.pos.x;  
var flagY = flag.pos.y;  
hero.moveXY(flagX, flagY);  
hero.pickUpFlag(flag);  
}  
else {  
if(enemy) {  
hero.attack(enemy);  
}  
}  
}  
simple right?

[Previous page](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767.md?page=1)

[Next page](https://discourse.codecombat.com/t/solved-siege-of-stonehold-help/1767.md?page=3)
