Summits Gate (Need Help)

Here is my code, I can’t figure out what I’m doing wrong. Can someone help me out?

var enemies, enemy;

var summonTypes = [“archer”];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};

this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
};

this.commandPaladin = function(paladin) {
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (this.health < this.maxHealth && paladin.canCast(“heal”)) {
this.command(paladin, “cast”, “heal”, this);
} else if (enemy) {
this.command(paladin, “attack”, enemy);
}
};

this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, “attack”, enemy);
} else {
this.command(soldier, “move”, {x: soldier.pos.x+10, y: soldier.pos.y});
}
};

this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, “attack”, enemy);
} else {
this.command(archer, “move”, {x: archer.pos.x+5, y: archer.pos.y});
}
};

this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, “attack”, enemy);
} else {
this.command(griffin, “move”, {x: griffin.pos.x+10, y: griffin.pos.y});
}
};

this.commandFriends = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == “soldier”) {
this.commandSoldier(friend);
} else if(friend.type == “archer”) {
this.commandArcher(friend);
} else if(friend.type == “griffin-rider”) {
this.commandGriffin(friend);
} else if(friend.type == “paladin”) {
this.commandPaladin(friend);
}
}
};

this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
}
}
}
if (enemy) {
this.attack(enemy);
}
else if (this.health == this.maxHealth) {
this.moveXY(hero.pos.x + 10, hero.pos.y + 1);
}
};

this.saveFriendsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, “move”, {x: 0, y: 40});
}
};
loop {
var friend = this.findFriends();
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
this.saveFriendsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
enemy = this.findNearestEnemy();
var warlock = this.findNearest(this.findByType(“warlock”));
var chieftain = this.findNearest(this.findByType(“chieftain”));
if (chieftain) {
while (chieftain.health > 0) {
this.attack(chieftain);
if (this.isReady(“chain-lightning”)) {
this.cast(“chain-lightning”, chieftain);
}
if (this.isReady(“bash”)) {
this.bash(chieftain);
}
if (friend) {
hero.command(friend, “attack”, chieftain);
}
}
}
}

P.S: My equipment includes: Softened Leather Boots; Sword of the Temple; Emperors Gloves; Simple Wristwatch; Leather Belt; Programmication IV; Enchanted Lenses; Quarts Sense Stone; Boss Star III; Worn Dragonplate Helm; Enameled Dragonplate Chestplate; Crude Spike.

Are you doing Python or JAVA Script?

i’m doing Javascript

You also need to use
https://screenshots.firefoxusercontent.com/images/29e4f42a-fce0-446c-9027-e4df97196d99.png
So I can see your code corectly. As far as I see you need to put spaces on your code with the {

FINE!!

var enemies, enemy;

var summonTypes = [“archer”];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};

this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
};

this.commandPaladin = function(paladin) {
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (this.health < this.maxHealth && paladin.canCast(“heal”)) {
this.command(paladin, “cast”, “heal”, this);
} else if (enemy) {
this.command(paladin, “attack”, enemy);
}
};

this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, “attack”, enemy);
} else {
this.command(soldier, “move”, {x: soldier.pos.x+10, y: soldier.pos.y});
}
};

this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, “attack”, enemy);
} else {
this.command(archer, “move”, {x: archer.pos.x+5, y: archer.pos.y});
}
};

this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, “attack”, enemy);
} else {
this.command(griffin, “move”, {x: griffin.pos.x+10, y: griffin.pos.y});
}
};

this.commandFriends = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == “soldier”) {
this.commandSoldier(friend);
} else if(friend.type == “archer”) {
this.commandArcher(friend);
} else if(friend.type == “griffin-rider”) {
this.commandGriffin(friend);
} else if(friend.type == “paladin”) {
this.commandPaladin(friend);
}
}
};

this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
}
}
}
if (enemy) {
this.attack(enemy);
}
else if (this.health == this.maxHealth) {
this.moveXY(hero.pos.x + 10, hero.pos.y + 1);
}
};

this.saveFriendsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, “move”, {x: 0, y: 40});
}
};
loop {
var friend = this.findFriends();
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
this.saveFriendsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
enemy = this.findNearestEnemy();
var warlock = this.findNearest(this.findByType(“warlock”));
var chieftain = this.findNearest(this.findByType(“chieftain”));
if (chieftain) {
while (chieftain.health > 0) {
this.attack(chieftain);
if (this.isReady(“chain-lightning”)) {
this.cast(“chain-lightning”, chieftain);
}
if (this.isReady(“bash”)) {
this.bash(chieftain);
}
if (friend) {
hero.command(friend, “attack”, chieftain);
}
}
}
}

OOPS

var enemies, enemy;
var summonTypes = [“archer”];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
};
this.commandPaladin = function(paladin) {
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (this.health < this.maxHealth && paladin.canCast(“heal”)) {
this.command(paladin, “cast”, “heal”, this);
} else if (enemy) {
this.command(paladin, “attack”, enemy);
}
};
this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, “attack”, enemy);
} else {
this.command(soldier, “move”, {x: soldier.pos.x+10, y: soldier.pos.y});
}
};
this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, “attack”, enemy);
} else {
this.command(archer, “move”, {x: archer.pos.x+5, y: archer.pos.y});
}
};
this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, “attack”, enemy);
} else {
this.command(griffin, “move”, {x: griffin.pos.x+10, y: griffin.pos.y});
}
};
this.commandFriends = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == “soldier”) {
this.commandSoldier(friend);
} else if(friend.type == “archer”) {
this.commandArcher(friend);
} else if(friend.type == “griffin-rider”) {
this.commandGriffin(friend);
} else if(friend.type == “paladin”) {
this.commandPaladin(friend);
}
}
};
this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
}
}
}
if (enemy) {
this.attack(enemy);
}
else if (this.health == this.maxHealth) {
this.moveXY(hero.pos.x + 10, hero.pos.y + 1);
}
};
this.saveFriendsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, “move”, {x: 0, y: 40});
}
};
loop {
var friend = this.findFriends();
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
this.saveFriendsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
enemy = this.findNearestEnemy();
var warlock = this.findNearest(this.findByType(“warlock”));
var chieftain = this.findNearest(this.findByType(“chieftain”));
if (chieftain) {
while (chieftain.health > 0) {
this.attack(chieftain);
if (this.isReady(“chain-lightning”)) {
this.cast(“chain-lightning”, chieftain);
}
if (this.isReady(“bash”)) {
this.bash(chieftain);
}
if (friend) {
hero.command(friend, “attack”, chieftain);
}
}
}
}

I think he meant the </>

OK!!

var enemies, enemy;
var summonTypes = [“archer”];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
};
this.commandPaladin = function(paladin) {
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (this.health < this.maxHealth && paladin.canCast(“heal”)) {
this.command(paladin, “cast”, “heal”, this);
} else if (enemy) {
this.command(paladin, “attack”, enemy);
}
};
this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, “attack”, enemy);
} else {
this.command(soldier, “move”, {x: soldier.pos.x+10, y: soldier.pos.y});
}
};
this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, “attack”, enemy);
} else {
this.command(archer, “move”, {x: archer.pos.x+5, y: archer.pos.y});
}
};
this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, “attack”, enemy);
} else {
this.command(griffin, “move”, {x: griffin.pos.x+10, y: griffin.pos.y});
}
};
this.commandFriends = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == “soldier”) {
this.commandSoldier(friend);
} else if(friend.type == “archer”) {
this.commandArcher(friend);
} else if(friend.type == “griffin-rider”) {
this.commandGriffin(friend);
} else if(friend.type == “paladin”) {
this.commandPaladin(friend);
}
}
};
this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
}
}
}
if (enemy) {
this.attack(enemy);
}
else if (this.health == this.maxHealth) {
this.moveXY(hero.pos.x + 10, hero.pos.y + 1);
}
};
this.saveFriendsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, “move”, {x: 0, y: 40});
}
};
loop {
var friend = this.findFriends();
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType(“catapult”));
if (catapult) {
this.saveFriendsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
enemy = this.findNearestEnemy();
var warlock = this.findNearest(this.findByType(“warlock”));
var chieftain = this.findNearest(this.findByType(“chieftain”));
if (chieftain) {
while (chieftain.health > 0) {
this.attack(chieftain);
if (this.isReady(“chain-lightning”)) {
this.cast(“chain-lightning”, chieftain);
}
if (this.isReady(“bash”)) {
this.bash(chieftain);
}
if (friend) {
hero.command(friend, “attack”, chieftain);
}
}
}
}

Close. Try copying it from the source - the Summit’s Gate level - and pasting it here just the way you did instead of copying it from this board. You’ll understand why as soon as you do; all the structure is retained and everyone can see it here exactly as it appears in the game.

You’re getting there.

thanks,

var enemies, enemy;
var summonTypes = ["archer"];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
    }
};
this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
        }
    }
return lowestFriend;
};
this.commandPaladin = function(paladin) {
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (this.health < this.maxHealth && paladin.canCast("heal")) {
this.command(paladin, "cast", "heal", this);
} else if (enemy) {
this.command(paladin, "attack", enemy);
    }
};
this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, "attack", enemy);
} else {
this.command(soldier, "move", {x: soldier.pos.x+10, y: soldier.pos.y});
    }
};
this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, "attack", enemy);
} else {
this.command(archer, "move", {x: archer.pos.x+5, y: archer.pos.y});
    }
};
this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, "attack", enemy);
} else {
this.command(griffin, "move", {x: griffin.pos.x+10, y: griffin.pos.y});
    }
};
this.commandFriends = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "soldier") {
this.commandSoldier(friend);
} else if(friend.type == "archer") {
this.commandArcher(friend);
} else if(friend.type == "griffin-rider") {
this.commandGriffin(friend);
} else if(friend.type == "paladin") {
this.commandPaladin(friend);
        }
    }
};
this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType("catapult"));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
        }
    }
}
if (enemy) {
this.attack(enemy);
}
else if (this.health == this.maxHealth) {
this.moveXY(hero.pos.x + 10, hero.pos.y + 1);
    }
};
this.saveFriendsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, "move", {x: 0, y: 40});
    }
};
loop {
var friend = this.findFriends();
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType("catapult"));
if (catapult) {
this.saveFriendsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
enemy = this.findNearestEnemy();
var warlock = this.findNearest(this.findByType("warlock"));
var chieftain = this.findNearest(this.findByType("chieftain"));
if (chieftain) {
while (chieftain.health > 0) {
this.attack(chieftain);
if (this.isReady("chain-lightning")) {
this.cast("chain-lightning", chieftain);
}
if (this.isReady("bash")) {
this.bash(chieftain);
}
if (friend) {
hero.command(friend, "attack", chieftain);
            }
        }
    }
}

that is a lot better.

I keep dieing near the chieftain because he can’t figure out what friend or chieftain is.

What hero are you using?