Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Long road please help :)

function onSpawn(event) {
 // Ukończ tą funkcję:
    while (true) {
        var item = pet.findNearestByType("potion");    // Nie zapomnij używać pętli "while-true"
    }
    if (item) {
        pet.fetch(item);
    }
    // If there's an item:
    // Use pet.fetch(item) to fetch the item.
    // Przypisz funkcję 'onSpawn'  do zdarzenia zwierzaka "spawn".
     pet.on("spawn", onSpawn);
   hero.moveXY(78, 35);
}

Hi, I got a problem with this level, it seems to work but it doesn't, plese help :slight_smile:
thx a lotPreformatted text

Have your hero find the potion, have your pet fetch it.

I change it, and it still doesn’t work

function onSpawn(event) {

// Ukończ tą funkcję:
while (true) {
var item = hero.findNearestItem();

//   var item = pet.findNearestByType("Potion");    // Nie zapomnij używać pętli "while-true"

if (item) {
    pet.fetch(item);
}

}

// If there's an item:
// Use pet.fetch(item) to fetch the item.
// Przypisz funkcję 'onSpawn'  do zdarzenia zwierzaka "spawn".

// pet.on(“spawn”, onSpawn);

 pet.on("spawn", onSpawn);

}
hero.moveXY(78, 35);

That looks like the proper code now, but can’t tell if your indentation is ok or not. Also, I am not familiar enough with JS to know if there might be a problem with your syntax.

Repost your code, so we can check the indents…hopefully someone more proficient with JS can take a look too.

function onSpawn(event) {
    while (true) {
        var item = hero.findNearestItem();
        if (item) {
            pet.fetch(item);
        }
    }
    pet.on("spawn", onSpawn);
}
hero.moveXY(78, 35);
Thats my code I wrote   var item = hero.findNearestItem(); 
as you told me and its still doesn't work, can anyone help  me??

Code does look good, but you need to move your ‘pet.on’ statement to the outside of the function definition.

thx a lot @dedreous now it works I passed the level :slight_smile: