[Adventurer] Sand mushrooms

Ok thanks :slightly_smiling_face:

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

could someone please tell me what’s wrong with this? They told me to look out for capitalization in someItem.

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

Make sure you indent everything inside the while loop, otherwise, the program will get confused.

You can do this by pressing the space button 4 times or pressing the tab button:

while True:
    someItem = hero.findNearestItem()
    if someItem and hero.health > hero.maxHealth / 3:
        # Collect the someItem:
        # You can do the rest
1 Like

1 Like

whats wrong? :slightly_frowning_face:

The while True loop to have your hero collect mushrooms looks fine to me. I think your problem is coming from the pet loop, even though your error is appearing on line 19. This section is incorrect:

potion = pet.findNearestItem("potion")
    if potion:
        pet.fetch("potion")

You are still trying to fetch a string and not an object. When you tell your pet to fetch “potion” you’re telling it to fetch a string of words that you have created. When you tell it to fetch potion, you’re telling it to fetch the nearest item you have found. Also, i believe your method

potion = pet.findNearestItem("potion") 

is incorrect. You said earlier that the default method was

potion = pet.findNearestByType("potion")

that is more than likely the correct method, since I don’t believe the findNearestItem() method takes any arguments. All that being said, keep the bottom loop the same, and change the pet loop to this:

def onSpawn(event):
    while True:
        potion = pet.findNearestByType("potion")
        if potion:
            pet.fetch(potion)

Hope this helps.

edit: Also, you should go back and practice earlier levels to try and get a better grip on what you have learned so far, so the future levels are easier for you.

2 Likes

Yes. Sorry if I meant to confuse you with findNearestItem. That was just an example.

Make sure you use pet.findNearestByType

1 Like

@Skillster thanks so much!!! :grin:

bye! :joy: :laughing:

My Raven isn’t picking things up and saying:
I can’t carry that!


Do I have to get the owl?

The crow should work fine. That’s not the problem. In line 7 you define potion. After defining the variable, you no longer need to type it as a string, as you have in line 9 & 10.

2 Likes

do i have to be subscriber?

Yes, the level Sand Mushrooms is subscriber only.
:lion: :lion: :lion: