def startsWith(phrase, word):
# If the word is longer than the text, return False.
if len(word) > len(text):
return False
# Loop through the indexes of word and text.
for i in len(word):
# If characters with the same index are different:
if i != phrase:
# Return False.
return False
# We checked all letters and they are the same.
# Return True.
return True
def onHear(event):
# Accept only options from experts.
if startsWith(event.speaker.id, "Exp"):
potion = pet.findNearestByType("potion")
if potion:
pet.fetch(potion)
pet.moveXY(28, 34)
pet.on("hear", onHear)
while True:
mushrooms = hero.findByType("mushroom")
nearest = hero.findNearest(mushrooms)
if nearest:
hero.moveXY(nearest.pos.x, nearest.pos.y)
Am I doing something wrong?
Lydia