# Forest cannon dancing help \[SOLVED\]

**URL:** <https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370>\
**Category:** Level Help\
**Created:** [April 12, 2021, 5:57pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370 "2021-04-12T17:57:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 5:57pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/1 "2021-04-12T17:57:00Z")

</div>

while True:  
pet.moveXY(48, 8)  
pet.moveXY(12, 8)  
onSpawn = pet.on(“spawn”, onSpawn)

# Cheer up your pet. Don’t remove this:

while True:  
hero.say(“Run!!!”)  
hero.say(“Faster!”)

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 5:59pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/2 "2021-04-12T17:59:06Z")

</div>

![Screen Shot 2021-04-12 at 12.58.21 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/9/6/966152006b8aa86cf8d6e83c34d6fe63b37812ba.png)

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 6:12pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/3 "2021-04-12T18:12:10Z")

</div>

It says that I didn’t cheer and my hero isn’t cheering on the pet

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [April 12, 2021, 6:21pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/4 "2021-04-12T18:21:20Z")

</div>

Instead of taking a picture of your code, you can use this button: \</\>

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 6:22pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/5 "2021-04-12T18:22:00Z")

</div>

```python
# Your pet should run back and forth on the X marks.
# The hero should cheer the whole time!

# Write the event function onSpawn for the pet.
# This function should make the wolf run back and forth:
# First, run to the right mark, then the left one:
while True:
    pet.moveXY(48, 8)
    pet.moveXY(12, 8)
    pass
onSpawn = pet.on("spawn", onSpawn)

while True:
    hero.say("Run!!!")
    hero.say("Faster!")
    pass

```

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 6:26pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/6 "2021-04-12T18:26:02Z")

</div>

Is it supposed to no work?

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [April 12, 2021, 6:31pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/7 "2021-04-12T18:31:00Z")

</div>

I would help you but

1. I’m a horrible coder
2. I can’t use pets
3. I’m pretty sure your in a level ahead of me or a subscriber level

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 6:31pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/8 "2021-04-12T18:31:53Z")

</div>

oh ok no problem. I am in a subscriber level, but thanks for trying to help me.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [April 12, 2021, 7:25pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/9 "2021-04-12T19:25:51Z")

</div>

> [@Reyansh\_Tandon](#):
>
> ```python
> while True:
> pet.moveXY(48, 8)
> pet.moveXY(12, 8)
> 
> ```

Replace this while true statement with a defining statement. You want to define onSpawn(), not have a while true statement. The second while true statement will never run if there is a while true statement before it.

```python
def onSpawn():
    while hero.time < 43:
        pet.moveXY(48, 8)
        pet.moveXY(12, 8)

```

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 7:39pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/10 "2021-04-12T19:39:39Z")

</div>

it says that it ran out of time

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [April 12, 2021, 8:33pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/11 "2021-04-12T20:33:53Z")

</div>

The abc help is OK and every number between 27 and infinity will also work.  
while True: is the usual way to command the pet to make repeatable actions:

```python
def onSpawn():
    # while hero.time < float("inf"):
    # while hero.time < 27:
    while True:
        pet.moveXY(48, 8)
        pet.moveXY(12, 8)
pet.on("spawn", onSpawn)
# default code follows , Don't remove it

```

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 12, 2021, 10:14pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/12 "2021-04-12T22:14:53Z")

</div>

```python
def onSpawn():
    while hero.time < 43:
        pet.moveXY(48, 8)
        pet.moveXY(12, 8)
    pass
onSpawn = pet.on("spawn", onSpawn)

while True:
    hero.say("Run!!!")
    hero.say("Faster!")
    pass

```

I did it and it made my pet go to my character

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [April 13, 2021, 12:32am UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/13 "2021-04-13T00:32:54Z")

</div>

Your current code works perfectly fine for me.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/1/c/1cb1fdf4e38f78f57d0cffc4b1d78624394e2601.jpeg)

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 13, 2021, 1:23pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/14 "2021-04-13T13:23:48Z")

</div>

> [@Reyansh\_Tandon](#):
>
> ```python
> def onSpawn():
> while hero.time < 43:
> pet.moveXY(48, 8)
> pet.moveXY(12, 8)
> pass
> onSpawn = pet.on("spawn", onSpawn)
> 
> while True:
> hero.say("Run!!!")
> hero.say("Faster!")
> pass
> 
> ```

for me it goes to mmy character

---

<div class="post-metadata">

**Author:** ![Reyansh\_Tandon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/reyansh_tandon/32/17771_2.png) [@Reyansh\_Tandon](https://discourse.codecombat.com/u/Reyansh_Tandon)\
**Post date:** [April 13, 2021, 2:11pm UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/15 "2021-04-13T14:11:49Z")

</div>

Thanks I just figured it out. I accidentally removed my cheer up part. LOL. Thanks @abc @xython @enPointe77 THANKS GUYS

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [April 14, 2021, 2:12am UTC](https://discourse.codecombat.com/t/forest-cannon-dancing-help-solved/28370/16 "2021-04-14T02:12:47Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
