Kelvintaph Crusader, my people just freeze!


#1

I have coded my people to attack the witch, but then they just freeze, this seem’s to be a common issue, but nothing on the forums is helping!(Mostly because everything is in Python :smile:!) Here’s my code:

// You can find friends through walls, but not enemies.
// Watch out for smooth, frictionless ice patches!
function heroAttack(){
    var enemies = hero.findNearest(hero.findByType("brawler"));
    hero.attack(enemies);
    hero.attack(enemies);
    hero.moveXY(8, 14);
    enemies = hero.findNearest(hero.findByType("catapult"));
    hero.moveXY(62, 16 );
    hero.attack(enemies);
    hero.attack(enemies);
    hero.moveXY(8, 14); 
    hero.moveXY(78, 14);
}
function alliesRetaliate(){
    var friends = hero.findFriends();
    var enemy = hero.findNearest(hero.findByType("witch"));
    
        for(var  i=0;i<friends.length;i++){
            var friend = friends[i];
            if(enemy.health > 0){
                hero.command(friend, "attack", enemy);
        }
        else {
             hero.command(friend, "attack", friend.findNearestEnemy());
            
        }
    }
}
    

    

alliesRetaliate();
heroAttack(); 

Any ideas? :confused:


#2

@me16 Are you checking if enemies / enemy has any targets? In other words make sure its not null before targeting.

Also check your equipment again. If the glasses you are wearing don’t see far enough you won’t be able to detect the enemies either.

I remember that one of the levels made me use different glasses equipment and that threw me off because I was so used to the infinity goggles that let you see everything.


#3

I have infinity glasses, but my entire code is designed around that basis.
I don’t check if it is null, but it’s not.

I think I know what my problem is. I only call my alliesRetaliate function
once, whereas I should call it in a loop.


#4

loop. yep that would help.
Sorry I missed that one.

If you don’t run the code in a loop it will only try once and it will end.