# Restless dead javascript

**URL:** https://discourse.codecombat.com/t/restless-dead-javascript/32139
**Category:** Level Help
**Created:** [February 18, 2022, 1:13pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139 "2022-02-18T13:13:58Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 19, 2022, 5:30pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/21 "2022-02-19T17:30:54Z")

</div>

i not really recom flag because my pc can’t handle codecombat so it become so laggy i can’t even click  
on a plce

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [February 19, 2022, 5:32pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/22 "2022-02-19T17:32:35Z")

</div>

hmm, then you should make a variable, set it to false, and then when you kill the yeti and collect the gems, you set it to true, if it is true, you move on, thats a way to do it with code

separate them to stages, thats what i mean, based on what you have done

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 19, 2022, 5:36pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/23 "2022-02-19T17:36:10Z")

</div>

ok i continue tommorow i gtg

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 24, 2022, 12:40pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/24 "2022-02-24T12:40:37Z")

</div>

maybe i should use the `var pos = []; pos[1] = 'x`: position.pos.x, ‘y’: position.pos.y  
and use hero.command(friend, “defend”, pos);

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 24, 2022, 12:41pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/25 "2022-02-24T12:41:37Z")

</div>

and if hero.health \< than hero health divide by 2  
then he has to backup and let his friend protecting him  
what do you think?

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 24, 2022, 2:19pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/26 "2022-02-24T14:19:29Z")

</div>

```python
// This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

// Find and defeat the yeti then gather its essence for the ritual.
// You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
// Stand at the summoning stone (red x) to begin summoning
// Novar summonTyw you just have to survive the undead hoard
var summonTypes = ['soldier', 'archer'];
var pos = [];
pos[1] = {'x': 53, 'y': 48};
pos[2] = {'x': 48, 'y': 43};

function attack(enemy) {
    if (enemy) {
        while (enemy.health > 0) {
            if (hero.distanceTo(enemy) > 10) {
                hero.jumpTo(enemy.pos);
            }
            else if (hero.isReady("bash")) {
                hero.bash(enemy);
            }
            else if (hero.canCast("chain-lightning", enemy)) {
                hero.cast("chain-lightning", enemy);
            }
            else {
                hero.attack(enemy);
            }
        }
    }
}

function summon() {
    var types = summonTypes[hero.built.length % summonTypes.length];
    if (hero.gold > hero.costOf(types)) {
        hero.summon(types);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "soldier") {
            commandSoldier(friend);
        }
        else if (friend.type == "archer") {
            commandArcher(friend);
        }
    }
}

function commandArcher(archer) {
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.distanceTo(enemy) < 14) {
        hero.command(archer, "attack", enemy);
    }
    else {
        hero.command(archer, "move", {'x': 49, 'y': 42});
    }
}

function commandSoldier(soldier) {
    var enemy = hero.findNearestEnemy();
    
    if (enemy) {
        hero.command(soldier, "attack", enemy);
    }
    else {
        hero.command(soldier, "defend", pos[0]);
    }
}

function range(start, end) {
    var ans = [];
    for (let i = start; i <= end; i++) {
        ans.push(i);
    }
    return ans;
}

function collect() {
    var item = hero.findNearestItem();
    while (item) {
        hero.move(item.pos);
        item = hero.findNearestItem();
    }
}

hero.moveXY(55, 10);
hero.wait(2);
attack(hero.findNearestEnemy());
collect();
hero.moveXY(55, 33);
hero.moveXY(49, 37);
hero.moveXY(19, 40);
for (var i in range(55, 48)) {
    summonTroops();
}
commandTroops();
hero.moveXY(55, 48);
if (hero.health < hero.maxHealth / 2.5) {
    hero.moveXY(33, 33);
}
while (true) {
    attack(hero.findNearestEnemy());
    commandTroops();
    collect();
}

```

here the code i put some of my ideas in here would you help me fix what this code wrong  
hero not summon anything.

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 24, 2022, 2:20pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/27 "2022-02-24T14:20:41Z")

</div>

i take the range function in this website that show me how to use range in javascript

```python
https://dev.to/ycmjason/how-to-create-range-in-javascript-539i

```

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 25, 2022, 6:51pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/28 "2022-02-25T18:51:50Z")

</div>

@Aya reply please need ur help

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [February 26, 2022, 6:08am UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/29 "2022-02-26T06:08:18Z")

</div>

Sorry, was busy earlier

You have the function of summoning troops defined differently than when you called it

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 26, 2022, 2:54pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/30 "2022-02-26T14:54:46Z")

</div>

oohhhh i confuse that thanks wait it doesn’t mean it solved yet

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 26, 2022, 2:58pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/31 "2022-02-26T14:58:18Z")

</div>

here the code still doesn’t summon

```python
// This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

// Find and defeat the yeti then gather its essence for the ritual.
// You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
// Stand at the summoning stone (red x) to begin summoning
// Novar summonTyw you just have to survive the undead hoard
var summonTypes = ['soldier', 'archer'];
var pos = [];
pos[1] = {'x': 53, 'y': 48};
pos[2] = {'x': 48, 'y': 43};

function attack(enemy) {
    if (enemy) {
        while (enemy.health > 0) {
            if (hero.distanceTo(enemy) > 10) {
                hero.jumpTo(enemy.pos);
            }
            else if (hero.isReady("bash")) {
                hero.bash(enemy);
            }
            else if (hero.canCast("chain-lightning", enemy)) {
                hero.cast("chain-lightning", enemy);
            }
            else {
                hero.attack(enemy);
            }
        }
    }
}

function summonTroops() {
    var types = summonTypes[hero.built.length % summonTypes.length];
    if (hero.gold > hero.costOf(types)) {
        hero.summon(types);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "soldier") {
            commandSoldier(friend);
        }
        else if (friend.type == "archer") {
            commandArcher(friend);
        }
    }
}

function commandArcher(archer) {
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.distanceTo(enemy) < 14) {
        hero.command(archer, "attack", enemy);
    }
    else {
        hero.command(archer, "move", {'x': 49, 'y': 42});
    }
}

function commandSoldier(soldier) {
    var enemy = hero.findNearestEnemy();
    
    if (enemy) {
        hero.command(soldier, "attack", enemy);
    }
    else {
        hero.command(soldier, "defend", pos[0]);
    }
}

function range(start, end) {
    var ans = [];
    for (let i = start; i <= end; i++) {
        ans.push(i);
    }
    return ans;
}

function collect() {
    var item = hero.findNearestItem();
    while (item) {
        hero.move(item.pos);
        item = hero.findNearestItem();
    }
}

hero.moveXY(55, 10);
hero.wait(2);
attack(hero.findNearestEnemy());
collect();
hero.moveXY(55, 33);
hero.moveXY(49, 37);
hero.moveXY(19, 40);
for (var i in range(55, 48)) {
    summonTroops();
}
commandTroops();
hero.moveXY(55, 48);
if (hero.health < hero.maxHealth / 2.5) {
    hero.moveXY(33, 33);
}
while (true) {
    attack(hero.findNearestEnemy());
    commandTroops();
    collect();
}

```

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [February 26, 2022, 2:58pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/32 "2022-02-26T14:58:46Z")

</div>

they weak compared too the enemy

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [February 26, 2022, 3:06pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/33 "2022-02-26T15:06:39Z")

</div>

I’ll recheck the code once I’m free

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [February 28, 2022, 6:39pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/34 "2022-02-28T18:39:34Z")

</div>

> [@Haris](#):
>
> `var types = summonTypes[hero.built.length % summonTypes.length];`

I’m not sure if making all of this for picking a type is necessary. I think pick either soldiers or archers, or you can make a for-loop for soldiers and another for archers

Also, why is this here?

> [@Haris](#):
>
> ```python
> function range(start, end) {
> var ans = [];
> for (let i = start; i <= end; i++) {
> ans.push(i);
> }
> return ans;
> }
> 
> ```

i think it is unnecessary

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [March 1, 2022, 4:19pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/35 "2022-03-01T16:19:37Z")

</div>

how do i get range in javascript?

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [March 1, 2022, 4:31pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/36 "2022-03-01T16:31:12Z")

</div>

I dont think there is, why do you need it tho?

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [March 1, 2022, 4:33pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/37 "2022-03-01T16:33:03Z")

</div>

> [@Haris](#):
>
> ```python
> for (var i in range(55, 48)) {
> summonTroops();
> }
> 
> ```

this look at this 20 char

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [March 1, 2022, 4:33pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/38 "2022-03-01T16:33:43Z")

</div>

i think this is the problem why hero not summoning

---

<div class="post-metadata">

### Author: ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)
#### Post date: [March 1, 2022, 4:35pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/39 "2022-03-01T16:35:41Z")

</div>

Probably that (20chars)

---

<div class="post-metadata">

### Author: ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)
#### Post date: [March 1, 2022, 4:36pm UTC](https://discourse.codecombat.com/t/restless-dead-javascript/32139/40 "2022-03-01T16:36:50Z")

</div>

i think the main problem is the range part it not working

[Previous page](https://discourse.codecombat.com/t/restless-dead-javascript/32139.md?page=1)

[Next page](https://discourse.codecombat.com/t/restless-dead-javascript/32139.md?page=3)
