# Sand Mushrooms Code Combat

**URL:** <https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134>\
**Category:** Level Help\
**Created:** [September 26, 2023, 4:48pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134 "2023-09-26T16:48:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rays244](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rays244/32/34962_2.png) [@rays244](https://discourse.codecombat.com/u/rays244)\
**Post date:** [September 26, 2023, 4:48pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/1 "2023-09-26T16:48:57Z")

</div>

I am getting stuck on the level Sand Mushrooms in CS3 (Desert).

You only have to fill out two lines it asks you to, and I do those, but for some reason, one of the lines that it gave us automatically seems to be not working.  
Here is my code:

#Collect 9 mushrooms.

#This function makes the pet fetch potions for you.  
def onSpawn(event):  
while True:  
# Pets can find the nearest item by its type.  
potion = pet.findNearestByType(“potion”)  
# Make the pet fetch the potion if it exists:  
**pet.fetch(potion)**

pet.on(“spawn”, onSpawn)

#Mushrooms are toxic, don’t collect them too quickly.  
while True:  
someItem = hero.findNearestItem()  
if someItem and hero.health \> hero.maxHealth / 3:  
# Collect the someItem:  
**hero.moveXY(someItem.pos.x, someItem.pos.y)**  
pass

I put the two lines in which they had us write out in bold. However, one of the lines that they gave us automatically “pet.on(“spawn”, onSpawn)” seems to have an error, saying that pet is not defined. This is making my hero not even move and I end up running out of time.

Any help appreciated, thanks! 🙂

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [September 26, 2023, 5:02pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/2 "2023-09-26T17:02:14Z")

</div>

```python
#Collect 9 mushrooms.

#This function makes the pet fetch potions for you.
def onSpawn(event):
while True:
# Pets can find the nearest item by its type.
potion = pet.findNearestByType(“potion”)
# Make the pet fetch the potion if it exists:
pet.fetch(potion)

pet.on(“spawn”, onSpawn)

#Mushrooms are toxic, don’t collect them too quickly.
while True:
someItem = hero.findNearestItem()
if someItem and hero.health > hero.maxHealth / 3:
# Collect the someItem:
hero.moveXY(someItem.pos.x, someItem.pos.y)
pass

```

i just formated it for you but pls format next time (its not a big deal but helps us help you)

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [September 26, 2023, 5:03pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/3 "2023-09-26T17:03:46Z")

</div>

also did you equip a pet

---

<div class="post-metadata">

**Author:** ![Learned](https://avatars.discourse-cdn.com/v4/letter/l/dec6dc/32.png) [@Learned](https://discourse.codecombat.com/u/Learned)\
**Post date:** [September 26, 2023, 6:17pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/4 "2023-09-26T18:17:22Z")

</div>

You have to spawn the pet first before you can command it. The code to spawn it in this case would be pet = game.spawnXY(“(pet name)”, x, y). Naturally, (pet name), x, and y would be replaced with the name of the pet and the coordinates you want to spawn it at.

---

<div class="post-metadata">

**Author:** ![ChickenMaster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chickenmaster/32/35104_2.png) [@ChickenMaster](https://discourse.codecombat.com/u/ChickenMaster)\
**Post date:** [September 27, 2023, 1:50pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/5 "2023-09-27T13:50:04Z")

</div>

Welcome, @rays244 to Code-Combat discourse! This place is where you can ask for help, get hints on levels, share experiences that you had while playing Code-Combat, reporting bugs, etc.! Feel free to enjoy your time here, but here’s a few things you should know before going ahead. Check this link out to learn more! [Welcome to CodeCombat Discourse Forums!](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601)?

---

<div class="post-metadata">

**Author:** ![rays244](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rays244/32/34962_2.png) [@rays244](https://discourse.codecombat.com/u/rays244)\
**Post date:** [September 27, 2023, 6:06pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/6 "2023-09-27T18:06:14Z")

</div>

My apologies, thanks

---

<div class="post-metadata">

**Author:** ![rays244](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rays244/32/34962_2.png) [@rays244](https://discourse.codecombat.com/u/rays244)\
**Post date:** [September 27, 2023, 6:06pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/7 "2023-09-27T18:06:46Z")

</div>

That fixed it! Thanks a lot!

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [September 27, 2023, 6:48pm UTC](https://discourse.codecombat.com/t/sand-mushrooms-code-combat/36134/8 "2023-09-27T18:48:34Z")

</div>

its fine like i said it just helps us help you
