Underground Business: pet.findNearestByType("gold-coin") always null

function onSpawn(event) {
    // Send the pet to walk around the dungeon:
    var coin = pet.findNearestByType("gold-coin")
    // Don't forget to return it to the hero:
    if (coin) {
    pet.fetch(coin)
    hero.coin = coin + 1
    }
}

pet.on("spawn", onSpawn);

while(true) {
    // Guard peasants:
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
    // When you have 300+ gold move to the red mark:
    if (hero.gold >= 300) {
        hero.moveXY(50, 34);
    }
}

You don’t need the hero.coin = coin + 1

I’ll remove it, but I still have the same problem:

The chest never fetches any coins.

The pet isn’t supposed to fetch the coins. Instead
the chest should move to all of the coins and once
it’s done collecting the coins he returns them to the hero

1 Like
function onSpawn(event) {
    // Send the pet to walk around the dungeon:
    var coin = pet.findNearestByType("gold-coin")
    // Don't forget to return it to the hero:
    if (coin) {
    pet.moveXY(coin.pos.x, coin.pos.y);
    pet.moveXY(hero.pos.x, hero.pos.y);
    }
}

pet.on("spawn", onSpawn);

while(true) {
    // Guard peasants:
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
    // When you have 300+ gold move to the red mark:
    if (hero.gold >= 300) {
        hero.moveXY(50, 34);
    }
}

This is straight from the Hints, and the chest still does not move to any of the coins.

Ya need the chest to walk around the whole dungeon(the place with the treasure) and then it should return all the treasures the hero.

1 Like