Hello. Help me plz. Why this code do not work?
var points = [];
points[0] = {x: 24, y: 62};
points[1] = {x: 24, y: 57};
points[2] = {x: 23, y: 50};
points[3] = {x: 23, y: 43};
points[4] = {x: 23, y: 36};
points[5] = {x: 23, y: 28};
this.pickUpCoin = function() {
var item = this.findNearest(this.findItems());
if(item){
this.move({x: item.pos.x, y: item.pos.y});
}
};
this.summonTroops = function() {
if(this.gold > 20) {
this.summon("soldier");
}
};
this.commandSoldier = function(friend) {
var enemies = this.findEnemies();
var enemy = friend.findNearest(enemies);
this.command(friend, "attack", enemy);
};
this.commandArcher = function(friend) {
var enemies = this.findEnemies();
var enemy = friend.findNearest(enemies);
for(i=0;i < points.length; i++) {
var point = points[i];
if(friend.distanceTo(enemy) < 25) {
this.command(friend, "attack", enemy);
this.command(friend, "move", {x: point.pos.x, y: point.pos.y});
}
}
};
loop {
this.pickUpCoin();
this.summonTroops();
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);
}
}
}