My issue has to do with the guardAct() function. I made an array to find the nearest monsters, but and classified it so that my guards would not cross onto the other side, but my guards won’t move at all. Please help.
There is also an error when the ai tries to read the x-pos of the enemy.
function guardAct(data) {
const guard = data.guard;
const place = data.place;
while (true) {
var enemyIndex = 0;
var enemies = guard.findMonsters();
while(enemyIndex < enemies.length){
var enemy = enemies[enemyIndex];
if (enemy) {
if(enemy.pos.x < 55){
guard.attack(enemy);
if(guard.isReady('roar')){
guard.special('roar');
}else if(guard.isReady('haste')){
guard.special('haste');
}else{
guard.attack(enemy);
}
}else{
enemyIndex +=1;
}
}
}
}
}
hero.on('spawn-guard', guardAct);
function begin(){
var archerBack = hero.build('archer', "A");
hero.setTargeting(archerBack, 'strong');
hero.build('cannon', 'B');
hero.build('cannon', 'C');
hero.special('push', 13, 51);
hero.build('archer', 'H');
hero.build('archer', 'I');
hero.special('teleport', 21, 51);
hero.build('archer', "F");
hero.build('archer', "G");
hero.build('mage', 'E');
hero.build('mage', 'D');
hero.special('pull', 40, 51);
hero.build('archer', 'A');
hero.special('teleport', 38, 51);
}
while(true){
begin();
}