I can’t get the pet to fetch to potions. What am I doing wrong? Thank you.
Move to the right side of the forest.
This function should check for items near the pet and fetch them.
def fetchPotions(event):
# Complete this function:
# Don’t forget to use a “while-true loop”:
while True:
item = hero.findNearestItem()
pet.fetch(item)
hero.moveXY(76, 35)
pass
Assign the function ‘fetchPotions’ for the pet event “spawn”.
while True:
pet.on(“spawn”, fetchPotions)
hero.moveXY(76, 35);
Problem ONE - the fetchPotion function makes imp to bring the potion to the hero but he does not dring it and imp hover indefinetky in the air with potion. when i have to add some “breaking” command to the function (lie the one behind //).
problem TWO the imp is carying potions, but the hero does not move (the program loops itself within the fetchPotions function)
is there posible to to make hero move ans imp simultanously brings potions to him?
i tried move the hero a bit and then fetch potion to him, but i ran out of time (and its not exactly by the book):
var item;
var item;
while (true) {
var X = hero.pos.x;
hero.moveXY(X + 16, 35);
item = pet.findNearestItem();
if (item) {
pet.fetch(item);
}
}