line 6: null is not an object (evaluating ‘tmp9[tmp10]’)
heres the code
loop {
var enemy = this.findNearestEnemy();
var flag = this.findFlag();
var flagPosition = flag.flagPosition;
var fy = flagPosition.y;
var fx = flagPosition.x;
this.moveXY(fx, fy);
if(this.isReady(“cleave”)){
this.cleave(enemy);
}
else{
this.attack(enemy);
this.shield();
this.warcry();
You need to put the code after enemy = line inside an if statement.
loop {
var enemy = this.findNearestEnemy();
var flag = this.findFlag();
if (flag) {
var flagPosition = flag.pos;
var fy = flagPosition.y;
var fx = flagPosition.x;
this.moveXY(fx, fy);
}
if (enemy) {
if(this.isReady("cleave")){
this.cleave(enemy);
} else {
this.attack(enemy);
this.shield();
this.warcry();
}
}
}
What is happening is an enemy (and flag) is not always there, so the object is null and trying to perform actions on a null will give you a script error. As a side note, you’re going to want to also add in the command to pickup a flag after you move to it.