Ok thanks
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
whats wrong?
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.
Yes. Sorry if I meant to confuse you with findNearestItem. That was just an example.
Make sure you use pet.findNearestByType
@Skillster thanks so much!!!
bye!
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.
do i have to be subscriber?
Yes, the level Sand Mushrooms is subscriber only.