// Your goal is to protect Reynaldo
// Find the paladin with the lowest health.
function lowestHealthPaladin() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = hero.findFriends();
for (var f = 0; f < friends.length; f++) {
var friend = friends[f];
if (friend.type != "paladin") {
continue;
}
if (friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
}
function commandPaladin(paladin) {
var enemy = paladin.findNearestEnemy();
// Heal the paladin with the lowest health using lowestHealthPaladin()
// You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
// Paladins can also shield: command(paladin, "shield")
// And don't forget, they can attack, too!
var needsHealing = lowestHealthPaladin();
if (needsHealing) {
hero.command(paladin, "cast", "heal", needsHealing);
} else {
hero.command(paladin, "shield");
hero.command(paladin, "attack", enemy);
}
}
function commandGriffin(griffin) {
var enemy = griffin.findNearestEnemy();
hero.command(griffin, "attack", enemy);
}
function commandPeasant(peasant) {
var item = peasant.findNearestItem();
hero.command(peasant, "move", item.pos);
}
function commandFriends() {
// Command your friends.
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
if (friend.type == "peasant") {
commandPeasant(friend);
} else if (friend.type == "griffin-rider") {
commandGriffin(friend);
} else if (friend.type == "paladin") {
commandPaladin(friend);
}
}
}
while (true) {
commandFriends();
// Summon griffin riders!
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
}
There are no errors but the level fails. What can I do to fix this?
Thanks
// Your goal is to protect Reynaldo
// Find the paladin with the lowest health.
function lowestHealthPaladin() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = hero.findFriends();
for (var f = 0; f < friends.length; f++) {
var friend = friends[f];
if (friend.type != "paladin") {
continue;
}
if (friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
}
function commandPaladin(paladin) {
var enemy = paladin.findNearestEnemy();
// Heal the paladin with the lowest health using lowestHealthPaladin()
// You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
// Paladins can also shield: command(paladin, "shield")
// And don't forget, they can attack, too!
var needsHealing = lowestHealthPaladin();
if (needsHealing) {
hero.command(paladin, "cast", "heal", needsHealing);
} else {
hero.command(paladin, "shield");
hero.command(paladin, "attack", enemy);
}
}
function commandGriffin(griffin) {
var enemy = griffin.findNearestEnemy();
hero.command(griffin, "attack", enemy);
}
function commandPeasant(peasant) {
var item = peasant.findNearestItem();
hero.command(peasant, "move", item.pos);
}
function commandFriends() {
// Command your friends.
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
if (friend.type === "peasant") {
commandPeasant(friend);
} else if (friend.type === "griffin-rider") {
commandGriffin(friend);
} else if (friend.type === "paladin") {
commandPaladin(friend);
}
}
}
while (true) {
commandFriends();
// Summon griffin riders!
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
}
I add the if statement, are there any other errors?
// Your goal is to protect Reynaldo
// Find the paladin with the lowest health.
function lowestHealthPaladin() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = hero.findFriends();
for (var f = 0; f < friends.length; f++) {
var friend = friends[f];
if (friend.type != "paladin") {
continue;
}
if (friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
}
function commandPaladin(paladin) {
var enemy = paladin.findNearestEnemy();
// Heal the paladin with the lowest health using lowestHealthPaladin()
// You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
// Paladins can also shield: command(paladin, "shield")
// And don't forget, they can attack, too!
var needsHealing = lowestHealthPaladin();
if (needsHealing) {
if (paladin.canCast("heal", needsHealing)) {
hero.command(paladin, "cast", "heal", needsHealing);
}
} else {
hero.command(paladin, "shield");
hero.command(paladin, "attack", enemy);
}
}
function commandGriffin(griffin) {
var enemy = griffin.findNearestEnemy();
hero.command(griffin, "attack", enemy);
}
function commandPeasant(peasant) {
var item = peasant.findNearestItem();
hero.command(peasant, "move", item.pos);
}
function commandFriends() {
// Command your friends.
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
if (friend.type === "peasant") {
commandPeasant(friend);
} else if (friend.type === "griffin-rider") {
commandGriffin(friend);
} else if (friend.type === "paladin") {
commandPaladin(friend);
}
}
}
while (true) {
commandFriends();
// Summon griffin riders!
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
}
Also, I don’t think there is always time for the paladin to shield before attacking. Maybe you could say when the paladin’s health is lower than a certain number they retreat and shield. I’ve seen other players do that.
function commandPaladin(paladin) {
var enemy = paladin.findNearestEnemy();
// Heal the paladin with the lowest health using lowestHealthPaladin()
// You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
// Paladins can also shield: command(paladin, "shield")
// And don't forget, they can attack, too!
var needsHealing = lowestHealthPaladin();
if (needsHealing) {
if (paladin.canCast("heal", needsHealing)) {
hero.command(paladin, "cast", "heal", needsHealing);
}
} else if (paladin.health < 20) {
hero.command(paladin, "shield");
} else {
hero.command(paladin, "attack", enemy);
}
}
This is my paladin function. Is there in issue in it?