Error when using command on soldiers in Java

public class AI {
    public static void main(String[] args) {
        while(true) {
            // Collect gold.
            var item = hero.findNearestItem();
            // If you have enough gold, summon a soldier.
            if ( > 20){
            // Use a for-loop to command each soldier.
            var friends = hero.findFriends();
            for(int friendIndex = 0; friendIndex < friends.length; friendIndex++) {
                var friend = friends[friendIndex];
                if(friend.type == "soldier") {
                    var enemy = friend.findNearestEnemy();
                    hero.command(friend, "move", {"x":74, "y":47});
                    hero.command(friend, "attack", enemy);
                    // If there's an enemy, command her to attack.
                    // Careful! If your soldiers are defeated, a warlock will appear!
                    // Otherwise, move her to the right side of the map.

When I run this code I get an error and I don’t know why. Plz help.

1 Like

Hello and welcome back to the Discourse. I don;t know the answer to your problem, but I have been having the same exact problem as you.

Overseer of the Deadly Truth


Can anyone help me. I’m having this problem on tons of levels. so I can’t exactly get any further.