# How to make pet move without delaying other instructions?

**URL:** <https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438>\
**Category:** Uncategorized\
**Created:** [March 22, 2022, 8:18pm UTC](https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438 "2022-03-22T20:18:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![k2adir](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@k2adir](https://discourse.codecombat.com/u/k2adir)\
**Post date:** [March 22, 2022, 8:18pm UTC](https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438/1 "2022-03-22T20:18:28Z")

</div>

I want to make the pet go some places on the map while my soldiers are attacking and such but using  
pet.move delays the next instruction. How could I make pet move and not delay the code?

here is an example for my function

```python
let flag = () =>{
    var flag = hero.findFlag("green");

 if(flag){
     pet.moveXY(flag.pos.x, flag.pos.y);
     }
    };

```

---

<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 23, 2022, 9:51pm UTC](https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438/2 "2022-03-23T21:51:45Z")

</div>

Use the pet.on(“spawn”,function) that controls your pet simultaneously with your hero.

---

<div class="post-metadata">

**Author:** ![herokolbert](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/herokolbert/32/34618_2.png) [@herokolbert](https://discourse.codecombat.com/u/herokolbert)\
**Post date:** [March 24, 2022, 12:01am UTC](https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438/3 "2022-03-24T00:01:22Z")

</div>

yep like this:  
this is python, ask someone to translate it.

```python
def onSpawn(event):
    unit = event.target
    flag = hero.findFlag("green")
    if flag:
        unit.moveXY(flag.pos.x, flag.pos.y)
pet.on("spawn", onSpawn)

```

---

<div class="post-metadata">

**Author:** ![k2adir](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@k2adir](https://discourse.codecombat.com/u/k2adir)\
**Post date:** [March 25, 2022, 1:54am UTC](https://discourse.codecombat.com/t/how-to-make-pet-move-without-delaying-other-instructions/32438/4 "2022-03-25T01:54:30Z")

</div>

thanks

```python
let onSpawn = (event) => {
unit = event.target;
flag = hero.findFlag("green");

if(flag){
unit.moveXY(flag.pos.x, flag.pos.y);
}
}
pet.on("spawn", onSpawn)

```

this should do the trick
