Kelvintaph Defliler, please help!

// The ogres are trapping you with their dark rituals!
// Your hero can't do anything besides command and move without angering the warlocks.
// Beware ice, robots, traps, antigravity fields, and other dark magic.
// Somehow, you'll need to defeat Nalfar and save your paladin.
// The great treasure of Kelvintaph awaits your victory.
var safe = false;
if (!safe) {
    hero.moveXY(33, 10);
}
while (true) {
          var paladin = hero.findNearestByType("palaidn")[0];
        for (var i = 0; i < paladin.length; i++) {
        var paladin = paladin[i];
        var friend = hero.findFriends();
        var enemy = paladin.findNearestEnemy();
        if (enemy) {
            hero.command(paladin, "cast", "heal", enemy);
        }
    var soldier = hero.findByType("soldier");
    for (var i = 0; i < soldier.length; i++) {
        var soldier = soldier[i];
        var friend = hero.findFriends();
        var enemy = soldier.findNearestEnemy();
        if (enemy) {
            hero.command(soldier, "attack", enemy);
        }
    }
            var archer = hero.findNearestByType("archer");
        for (var i = 0; i < archer.length; i++) {
        var archer = archer[i];
        var friend = hero.findFriends();
        var enemy = archer.findNearestEnemy();
        if (enemy) {
            hero.command(archer, "attack", enemy);
        }

    }
}
}

This is what happens:

@AnSeDra, @dedreous and @Deadpool198 please help!

Heal the paladin, try to shield and cast heal on the paladin not on the enemy.

yes but the problem is that i will not do anything because of the eror

Put findByType instead of findNearestbyType.

That should fix the error

Oh ok let me try that

Do you get the same error?

No more errors but they dont do anything

So its like i didntcommmand them

The paladin is not healing

Maybe there is no enemy??

yes there is Nalfar(20 chars)

I removed the if eneemy but paladin still does not heal

can you post your armor

Here is his armor

And he got infinite loop detected.

var paladin = hero.findByType("palaidn")[0];

Check your spelling in this line.

var paladin = paladin[i];

Does it do odd things to the loop to redefine the variable?

i got infinite loop detected(the level code has infinite loop, not my code)

I already told them that.