Bug On Underground Buissness?


#1

So… Below Is My Code. It Should Work, But I get a Message Saying “Try hero.pos” On Line 18. I Don’t Know Why! Is This A Bug? Please Help.

// Accumulate 300 gold and escape from the dungeon.

function onSpawn(event) {
    // Send the pet to walk around the dungeon:
    var coin = pet.findNearestByType("gold-coin");
    pet.moveXY(coin.pos.x,coin.pos.y);
    // Don't forget to return it to the hero:
    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);
        }
}


#2

It’s a bug in your code. You try to send the pet to coin. Are you sure that a coin exists?


#3

Before I Talk About The Code, I want to tell this is the same guy as The99thMage, I forgot my password and the reset email didn’t come. Well, Now I used This:

if(coin){
    pet.moveXY(coin.pos.x,coin.pos.y);
}

But Now The Mimic Pet Moves Just A Little Before stopping


#4

You pet doesn’t see any coin so as the result it’s moving to the hero position.

Have you read comments/instructions? Why do you want use coin.pos?


#5

I am struggling a bit too. Are we supposed to manually instruct the pet to move around the box using moveXY and hardcoding in the parameters? If not, how come my pet cannot see “coin”.

    var coin = pet.findNearestByType("gold-coin");
    if (coin) {
        pet.moveXY(coin.pos.x, coin.pos.y);
    }

I put that inside onSpawn().


#6

For the current level it’s the best way. If you will try to follow by coins without any condition your pet will stuck.