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

Long Road (java script)

My code doesn’t seem to work and I don’t know what the error is. Any help?

// Move to the right.
hero.moveXY(76, 35);
// Complete this function:
function onSpawn(event){
    // Inside a while-true loop:
    while(true) {
        
    }
        // Use hero.findNearestItem()
        var item = hero.findNearestItem();
        
        // If there's an item:
        if (item) {
            
        }
            // Use pet.fetch(item) to fetch the item.
            pet.fetch(item);
}

// Use pet.on() to assign onSpawn to the "spawn" event
pet.on("spawn", onSpawn);
hero.moveXY(78, 35);

it’s your move statements. Think of ‘moveXY’ as a fire and forget method…once it fires, no other code will run until the moveXY has completed.

Try deleting the first move statement.

Just noticed…got a couple other ‘gotchas’ too.

You close the ‘while true’ loop before any other code can be ran.
Your ‘pet.fetch’ line is outside of your if block.

thank you that was all of my problems.:slightly_smiling_face:

1 Like