Sand Mushrooms Code Combat

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! :slight_smile:

#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)

also did you equip a pet

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.

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!?

My apologies, thanks

That fixed it! Thanks a lot!

its fine like i said it just helps us help you