Long Road bug hero doesn't move


#1

Hi there,

I don’t know if it’s my code or a bug with the game itself.
But I ran the scenario without my code being put in and my hero started moving from left to right.
After I put my code in, my hero stopped moving at all, he stands in the starting place and dies.
Plz help, this is my code i wrote:

// Loop naar de rechter kant van het bos.

// Deze functie moet checken of er items in de buurt zijn van je huisdier en die ophalen.
function fetchPotions(event){
    // Maak deze functie af:
    var item = hero.findNearestItem();
        // Vergeet niet een "while-true loop" te gebruiken.
        while(true) {
        // If there's an item:
        if (item){
            pet.fetch(item);
        }
        }
            // Use pet.fetch(item) to fetch the item.
            
}

// Wijs de functie 'fetchPotions' toe aan het event "spawn" van je huisdier (pet).
fetchPotions("spawn");
hero.moveXY(78, 35);

#2

Have you played levels before about how to assign event handlers?

You are trying to call fetchPotions function which contains while-true loop. It stops your further code.

You need to assign the event handler with pet.on method.;


#3

ty for your reply,

I have got it working now, only my pet picksup the first item and not the second item, in which my hero dies.
This is my code now:

function fetchPotions(event){
    var item = pet.findNearestItem();
        while(true) {
        if (item){
            pet.fetch(item);
        }
        }
}
pet.on("spawn", fetchPotions);
 hero.moveXY(78, 35);

#4

Move this line
var item = pet.findNearestItem();
into while-true loop