# hero.spawnXY VS. game.spawnXY for adding a hero to the game - The Difference? PYTHON

**URL:** https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309
**Category:** Ambassador
**Created:** [March 30, 2018, 10:42am UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309 "2018-03-30T10:42:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AnitaOlsen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anitaolsen/32/40385_2.png) [@AnitaOlsen](https://discourse.codecombat.com/u/AnitaOlsen)
#### Post date: [March 30, 2018, 10:42am UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309/1 "2018-03-30T10:42:25Z")

</div>

A question from the Game Development 2: 1.Guard Duty level. I wrote game.spawnXY instead of hero.spawnXY but it is still working as it should (this is why I did not notice the difference in the code at first). So I am wondering, since both of them works in this code, what is the difference between using hero.spawn and game.spawn when it comes to adding a hero to the game?

I wrote:  
def soldierLogic():  
while True:  
enemy = soldier.findNearestEnemy()

```
    if enemy:
        soldier.attack(enemy)

    else:
         soldier.moveXY(42, 48)

```

# This assigns your spawned unit to the soldier variable.

**soldier = game.spawnXY(“soldier”, 42, 48)**

soldier.on(“spawn”, soldierLogic

I compared with:  
HINT 1

def soldierLogic():  
while True:  
enemy = soldier.findNearestEnemy()  
if enemy:  
soldier.attack(enemy)

**soldier = hero.spawnXY(“soldier”, 42, 48)**  
soldier.on(“spawn”, soldierLogic)

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [March 30, 2018, 10:03pm UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309/2 "2018-03-30T22:03:21Z")

</div>

Please format your code using \</\>.

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [March 30, 2018, 10:03pm UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309/3 "2018-03-30T22:03:35Z")

</div>

![41%20PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/4/4717486a18ae7a4d8bed049ce3f3e7f51d5bfbd5.jpg)

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)
#### Post date: [March 31, 2018, 3:36am UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309/4 "2018-03-31T03:36:29Z")

</div>

Hello there! The difference is, is that `hero.spawnXY()`sets whatever you spawned to be your hero. So you can move it around by clicking the map. While `game.spawnXY()` just spawns it as a thang with an AI controlled code and next time be sure to use \</\> to preformat your code so it’s easier for us to see your code. If you are unsure about how to do this, check the official FAQ.

[https://discourse.codecombat.com/faq](https://discourse.codecombat.com/faq)

---

<div class="post-metadata">

### Author: ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)
#### Post date: [April 3, 2018, 3:45pm UTC](https://discourse.codecombat.com/t/hero-spawnxy-vs-game-spawnxy-for-adding-a-hero-to-the-game-the-difference-python/14309/5 "2018-04-03T15:45:29Z")

</div>

🤨  
Isn’t the hero spawning made with `game.spawnHeroXY(x,y)`?
