# Game Development 2 Level 27 "Game Of Coins Step 3: Enemies"

**URL:** <https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785>\
**Category:** Level Help\
**Created:** [May 24, 2020, 6:48pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785 "2020-05-24T18:48:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BingoPerroso](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bingoperroso/32/12381_2.png) [@BingoPerroso](https://discourse.codecombat.com/u/BingoPerroso)\
**Post date:** [May 24, 2020, 6:48pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/1 "2020-05-24T18:48:45Z")

</div>

So I’ve been stuck in this level for a while. My struggle is that I’m only missing one goal to pass the level and it is “Scouts should be able to one hit the hero”. Here is the code:

````python

// The game layout and items. Scroll down.
game.spawnXY("forest", 16, 16);
game.spawnXY("forest", 32, 16);
game.spawnXY("forest", 48, 16);
game.spawnXY("forest", 64, 16);
game.spawnXY("forest", 16, 32);
game.spawnXY("forest", 32, 32);
game.spawnXY("forest", 48, 32);
game.spawnXY("forest", 64, 32);
game.spawnXY("forest", 16, 48);
game.spawnXY("forest", 32, 48);
game.spawnXY("forest", 48, 48);
game.spawnXY("forest", 64, 48);

game.spawnXY("bronze-coin", 16, 8);
game.spawnXY("bronze-coin", 24, 8);
game.spawnXY("bronze-coin", 32, 8);
game.spawnXY("bronze-coin", 48, 8);
game.spawnXY("bronze-coin", 56, 8);
game.spawnXY("bronze-coin", 64, 8);
game.spawnXY("bronze-coin", 72, 8);

game.spawnXY("bronze-coin", 8, 16);
game.spawnXY("bronze-coin", 24, 16);
game.spawnXY("bronze-coin", 40, 16);
game.spawnXY("bronze-coin", 56, 16);
game.spawnXY("bronze-coin", 72, 16);

game.spawnXY("bronze-coin", 8, 24);
game.spawnXY("bronze-coin", 16, 24);
game.spawnXY("bronze-coin", 24, 24);
game.spawnXY("bronze-coin", 32, 24);
game.spawnXY("bronze-coin", 40, 24);
game.spawnXY("bronze-coin", 48, 24);
game.spawnXY("bronze-coin", 56, 24);
game.spawnXY("bronze-coin", 64, 24);
game.spawnXY("bronze-coin", 72, 24);

game.spawnXY("bronze-coin", 24, 32);
game.spawnXY("bronze-coin", 56, 32);

game.spawnXY("bronze-coin", 8, 40);
game.spawnXY("bronze-coin", 16, 40);
game.spawnXY("bronze-coin", 24, 40);
game.spawnXY("bronze-coin", 32, 40);
game.spawnXY("bronze-coin", 40, 40);
game.spawnXY("bronze-coin", 48, 40);
game.spawnXY("bronze-coin", 56, 40);
game.spawnXY("bronze-coin", 64, 40);
game.spawnXY("bronze-coin", 72, 40);

game.spawnXY("bronze-coin", 8, 48);
game.spawnXY("bronze-coin", 24, 48);
game.spawnXY("bronze-coin", 40, 48);
game.spawnXY("bronze-coin", 56, 48);
game.spawnXY("bronze-coin", 72, 48);

game.spawnXY("bronze-coin", 8, 56);
game.spawnXY("bronze-coin", 16, 56);
game.spawnXY("bronze-coin", 24, 56);
game.spawnXY("bronze-coin", 32, 56);
game.spawnXY("bronze-coin", 48, 56);
game.spawnXY("bronze-coin", 56, 56);
game.spawnXY("bronze-coin", 64, 56);
game.spawnXY("bronze-coin", 72, 56);

game.spawnXY("mushroom", 40, 8);
game.spawnXY("mushroom", 8, 32);
game.spawnXY("mushroom", 72, 32);
game.spawnXY("mushroom", 40, 56);

game.score = 1000;
ui.track(game, "time");
ui.track(game, "score");
// Lets simplify the game while we don't have power-ups.
game.addCollectGoal(10);
game.addSurviveGoal();

var player = game.spawnPlayerXY("knight", 8, 8);
player.maxSpeed = 32;

function onCollect(event) {
    var player = event.target;
    var item = event.other;
    if (item.type == "bronze-coin") {
        game.score += 1;
    }
    if (item.type == "mushroom") {
        game.score += 5;
    }
}

player.on("collect", onCollect);

// Spawn a monster "generator" in the center:
game.spawnXY("generator", 40, 32);
// Set the generator spawnType to “scout”.
"generator".spawnType = "scout";
// Set the generator spawnDelay to 6 (or greater).
"generator".spawnDelay >= 6;

// This function configures new spawned scouts.
function onSpawn(event) {
    var unit = event.target;
    unit.maxSpeed = 8;
    // Set the unit's attackDamage to a value that
    // is greater than or equal to the player's maxHealth.
    unit.attackDamage >= player.maxHealth;
}

// Set the handler for "scout"s' "spawn" event to onSpawn
game.setActionFor("scout", "spawn", onSpawn);

function checkTimeScore() {
    game.score -= 0.5;
    if (game.score < 0) {
        game.score = 0;
    }
}

while (true) {
    checkTimeScore();
}
// Win the game.```

I've also tried another method that essentially make the scouts one hit the player by using:
```player.maxHealth = 1;```
But still. The last goal won't ligth up.

Could this perhaps be a bug or am I doing things the way they aren't supposed to be done?
Thanks in advance.
````

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 24, 2020, 7:14pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/2 "2020-05-24T19:14:30Z")

</div>

Howdy and welcome to the forum!

First problem is that you need to define a variable name as your generator. With this, you can then set/change attributes. You have:

```javascript
// Spawn a monster "generator" in the center:
game.spawnXY("generator", 40, 32);
// Set the generator spawnType to “scout”.
"generator".spawnType = "scout";
// Set the generator spawnDelay to 6 (or greater).
"generator".spawnDelay >= 6;

```

“generator” is actually a literal string, not a variable…it will never change. Instead, define a variable to equal the generator, like:

```javascript
gen = game.spawnXY() // you know the proper code for this

```

Then, where ever you have “generator”, replace this with the variable name you came up with.

Second problem:

```javascript
// is greater than or equal to the player's maxHealth.

```

is perhaps a bit misleading. The statement you use is using a comparative, rather than a definitive function. Instead of “\>=”, as implied by the comments, you should use just “=”. The first is used to compare one value against another; the second assigns a value.

---

<div class="post-metadata">

**Author:** ![BingoPerroso](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bingoperroso/32/12381_2.png) [@BingoPerroso](https://discourse.codecombat.com/u/BingoPerroso)\
**Post date:** [May 24, 2020, 7:26pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/3 "2020-05-24T19:26:30Z")

</div>

Yup. that worked.  
You’ve saved me from the danger of losing computer science and the school year together with it!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 24, 2020, 7:28pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/4 "2020-05-24T19:28:33Z")

</div>

Glad to hear…good luck with your studies too! 🙂

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 25, 2020, 8:21pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/5 "2020-05-25T20:21:34Z")

</div>

Wow @dedreous your so good at code u solve everyone’s problems

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 25, 2020, 8:32pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/6 "2020-05-25T20:32:44Z")

</div>

Thanks Jeremy…I wouldn’t say I’m good, I just have formal training and 40+ years of practice at it 😉

If you’d like to discuss this further, let’s take it to PM’s please…I don’t think everyone else will necessarily want to listen. 😜

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 25, 2020, 9:14pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/7 "2020-05-25T21:14:40Z")

</div>

what’s PM(20 characters)

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 25, 2020, 9:25pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/8 "2020-05-25T21:25:13Z")

</div>

Private Message…click on my pic and you’ll see a blue message button. This sends a PM.

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/30491ba02d40f22321015da5313cd6813a4a38a4.png)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 25, 2020, 9:25pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/9 "2020-05-25T21:25:46Z")

</div>

Oh I am gonna try it

---

<div class="post-metadata">

**Author:** ![hooram](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hooram/32/47542_2.png) [@hooram](https://discourse.codecombat.com/u/hooram)\
**Post date:** [February 28, 2026, 4:46pm UTC](https://discourse.codecombat.com/t/game-development-2-level-27-game-of-coins-step-3-enemies/21785/10 "2026-02-28T16:46:53Z")

</div>

> [@dedreous](#):
>
> Howdy and welcome to the forum!
> 
> First problem is that you need to define a variable name as your [generator](https://nulsbrawl.fr/). With this, you can then set/change attributes. You have:
> 
> ```python
> // Spawn a monster "generator" in the center:
> game.spawnXY("generator", 40, 32);
> // Set the generator spawnType to “scout”.
> "generator".spawnType = "scout";
> // Set the generator spawnDelay to 6 (or greater).
> "generator".spawnDelay >= 6;
> 
> ```
> 
> “generator” is actually a literal string, not a variable…it will never change. Instead, define a variable to equal the generator, like:
> 
> ```python
> gen = game.spawnXY() // you know the proper code for this
> 
> ```
> 
> Then, where ever you have “generator”, replace this with the variable name you came up with.
> 
> Second problem:
> 
> ```python
> // is greater than or equal to the player's maxHealth.
> 
> ```
> 
> is perhaps a bit misleading. The statement you use is using a comparative, rather than a definitive function. Instead of “\>=”, as implied by the comments, you should use just “=”. The first is used to compare one value against another; the second assigns a value.

Yeah that makes sense now you were treating “generator” like a variable when it’s just a string, so nothing was actually updating. Switching to a proper variable and fixing the assignment instead of comparison did the trick worked for me too.
