How to (fast and ugly) debug with the pet

The level is Summits Gate using Twilight glasses. You can find and name the Catapults and the Doors this way:

function debugCata(){
    while (true){
        var catapults = hero.findByType("catapult");
        if (catapults.length == 2)
         pet.debug(catapults[0].id + " = catapults[0]" + catapults[0].pos.y+ "\n"  + 
                   catapults[1].id + " = catapults[1]" + catapults[1].pos.y);
    }
}
function debugDoor(){
    while (true){
        var doors = hero.findByType("door");
        if (doors.length == 3)
         pet.debug(doors[0].id + "=doors[0]" + doors[0].pos.x + "\n"  +
                   doors[1].id + "=doors[1]" + doors[1].pos.x+ "\n"  + 
                   doors[2].id + " = doors[2]" + doors[2].pos.x);
    }
}
pet.on("spawn", debugCata);  
// pet.on("spawn", debugDoor);
var catapults = hero.findByType("catapult"),
    doors = hero.findByType("door");

First run pet.on(“spawn”, debugCata)


Name the two catapults:

var Catapult1 = catapults[0],
     Catapult = catapult [1];
// this is outside of the while (true) loop

then comment the pet.on(“spawn”, debugCata) and uncomment pet.on(“spawn”, debugDoor)


Name the doors:

var Gate = doors[2],
      InnerGate = doors[1],
      SanctumGate = doors[0];

then you can use these objects in the while true loop:

while (true){
  // code for catapults and ogres
  if (Gate.health > 0)
    hero.attack(Gate);
  else break;
}

Using the hero.say, hero.debug and pet.say is inferior to this method IMO.
For example pet.say will freeze your pet:
изображение

… Nothing can compare to the versatility of the Debug Console

6 Likes

super cool, thanks. :slightly_smiling_face:

3 Likes