Pet engineer, code doesn't work


Everytime the enemy comes, my pet doesn’t move at all.
This is my code:

// Move your pet to the left or right button as needed.

function onHear(event) {
    // Find the guards to listen to.
    var archer = pet.findNearestByType("archer");
    var soldier = pet.findNearestByType("soldier");
    // If event.speaker is the archer:
    if (event.speaker && "hear" == "archer") {
        hero.moveXY(32, 30);
        // Move to the left button.
    // If event.speaker is the soldier:
    if (event.speaker && "hear" == "soldier") {
        hero.moveXY(48, 30);
        // Move to the right button.

pet.on("hear", onHear);

// You don't have to change the code below.
// Your hero should protect the bottom right passage.
while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {


Are you moving the hero or the pet in the pet onHear function?


going to do that
(post needs 20 characters)


ok, I changed it, but the pet still won’t move. Is there anything wrong with the hear thing?


Place this into your code


after the var soldier = pet.findNearestByType("soldier"); and ask yourself how the if statement should be created.


I will. I’ll reply after.