Long Road Help Please


#1

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


#2

Remove hero.moveXY(76,35) from def fetchPotions(event), check if item exists and remove second while True.


#3

Hi, i have similar problem.

according to the help the syntax should be like this:

function fetchPotions(event) {
while (true) {
var item = pet.findNearest(hero.findItems());
pet.fetch(item);

                     // pet.moveXY(10, 10);
}

}
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);
}
}

thank you.


#4

The problem with the first example is here:

pet.on("spawn", fetchPotions());

fetchPotions() calls the function, instead of passing it into the pet.on function by reference.

Remove the () from the end of fetchPotions and it should work.


#5

aaah … thanks, got it finally, even though it still reads an error i was able to got through.