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

Summit's Gate - Javascript Help

// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function summonUnits() {
    if (hero.gold >= hero.costOf("griffin-rider")) {
        hero.summon("griffin-rider");
    } else {
        var summonable = null;
    }
}
function commandUnits(friends) {
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "paladin") {
            commandPaladin(friend);
        } else if (friend.type == "archer") {
            commandArcher(friend);
        } else if (friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if (friend.type == "soldier") {
            commandSoldier(friend);
        } else {
            var commandable = null;
        }
    }
}
function commandArcher(archer) {
    var enemy = archer.findNearestEnemy();
    if (enemy) {
        hero.command(archer, "attack", enemy);
    }
    if (archer.health < 10) {
        hero.brew("heal", archer);
    }
}
function commandPaladin(paladin) {
    var enemy = paladin.findNearestEnemy();
    if (paladin.health < 100) {
        if (paladin.canCast("heal")) {
            hero.command(paladin, "cast", "heal", paladin);
        } else {
            hero.command(paladin, "shield");
        }
    } else {
        hero.command(paladin, "attack", enemy);
    }
}
function commandGriffin(griffin) {
    var enemy = griffin.findNearestEnemy();
    if (enemy) {
        hero.command(griffin, "attack", enemy);
    }
    if (griffin.health < 50) {
        hero.brew("heal", griffin);
    }
}
function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.type == "catapult") {
        hero.command(soldier, "attack", enemy);
    } else {
        hero.command(soldier, "move", {
            x: soldier.pos.x + 5,
            y: soldier.pos.y
        });
    }
    var catapults = hero.findByType("catapult");
    for (var i = 0; i < catapults.length; i++) {
        var catapult = catapults[i];
        if (catapult.health <= 0) {
            hero.command(soldier, "attack", enemy);
        }
    }
}
function heroAction() {
    var enemy = hero.findNearestEnemy();
    if (enemy.type == "tower") {
        if (hero.distanceTo("enemy" > 29)) {
            hero.moveXY(enemy.pos.x - 29, hero.pos.y);
        } else if (hero.canCast("disintegrate", enemy)) {
            hero.cast("disintegrate", enemy);
        } else {
            hero.attack(enemy);
        }
    }
}
while (true) {
    var friends = hero.findFriends();
    summonUnits();
    commandUnits(friends);
    heroAction();
}

I breach the outer gate, however the hero does not disintegrate or move toward the beam towers. I have enchanted lenses. What do I do to fix this? (No error) I might need help in future parts of summits gate.
Thanks

Anybody there? Hello!

You hero is doing nothing because of typo:

function heroAction() {
// code
        if (hero.distanceTo("enemy" > 29)) //code

preserving your code and with the simplest for the hero

    var enemy = hero.findNearestEnemy();
    if (enemy) hero.attack(enemy) ;

you can reach the Inner Sanctum


but you lose so many soldiers…
didn’t try but i think you need only paladins and archers, i passed the level with a free hero, without summoning any and without losing any unit.
See Jenny's method - stacking while true loops: Summit Gate? how the level can be divided into several while true loops

Has anybody tested the new brew ability?

3 Likes

I have used the explosion and heal abilities, could you please put that in Javascript?
Should I use the twilight glasses?
This is my new code for heroAction

function heroAction() {
    var enemy = hero.findNearestEnemy();
   if (enemy) {
       hero.attack(enemy);
   }
   if (hero.canCast("poison-cloud",enemy)) {
       hero.cast("poison-cloud", enemy);
   }
   if (hero.health < 500) {
       hero.brew("heal",hero);
   }
}

I breach the outer gate but get killed shortly after. @xython

1 Like

I never played with this hero and till now i have negative feelings about his “new” abilities. Using “brew” Omarn is attacked by his wolf. I think this was supposed to happen only when skeletons are summoned. Not a fan of stacking ifs and your main goal is to stay alive. Your function can be modified to

function heroAction() {
   var enemy = hero.findNearestEnemy();
   if (hero.health < 500) 
       hero.brew("heal",hero);
   else if (enemy) {
      if (hero.canCast("poison-cloud",enemy)) 
         hero.cast("poison-cloud", enemy);
      else
         hero.attack(enemy);
   }
}

but using the above function you will die being too close to towers
so used only attack with Vine Staff ( you can equip also the Lightning Twig ( i’m a big fan of it) but it will be slower. I also modified all minion’s attack functions. They don’t need to attack the enemies when their positions are in the second battlefield.

function heroAction() {
   var enemy = hero.findNearestEnemy();
   if (hero.health < hero.maxHealth && hero.isReady("brew")) // only for testing
       hero.brew("heal",hero); // you really don't need it
   else if (enemy) 
       hero.attack(enemy);
}

function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.pos.x < 100){
   // code
    }
 }

the result is displayed in an ugly quick gif

Can you use the console? Did you see the link from the previous post and do you understand it?

1 Like

I can not use the console and I do not understand the link.

Your hero, twilight glasses, cheap weapon, no brew gimmicks, no casualties, using the method from the link in the post
изображение
OmSGsmall

What do you don’t understand from the link?
Why you cannot use the console?

1 Like

The inspect menu is blocked on my school chromebook, and I don’t get how you stack while true loops.

Can you use this method How to unblock inspect element - Quora?

Chromebooks don’t have function (f) buttons.

see How to (fast and ugly) debug witht he pet
You can stack while true loops this way:

// code
var  doors = hero.findByType("door");
var Gate = doors[2],
    InnerGate = doors[1],
    SanctumGate = doors[0];
// code
while (true){
  // code for catapults and ogres
  if (Gate.health > 0)
    hero.attack(Gate);
  else break;
}
// code
while (true){
  // code
  if (InnerGate .health > 0)
    hero.attack(InnerGate );
  else break;
}
// code....

WHat does the console and debug do?

You can debug your code more successfully, find the Ids, health, positions and their relations with a specific array, find mistakes. Something like this is shown here: HELP Kelvintaph Crusader - #70 by xython (sorry - python )