I am having trouble with my code, it is only attacking the enemy not the chest. My code is so far (with the problem):
loop {
enemy = this.findNearestEnemy();
var distance = this.distanceTo("Chest");
if (distance < 10) {
if ( this.isReady("cleave")) {
this.cleave(enemy);
} else {
this.attack(enemy);
}
if (enemy) {
this.attack("Chest");
}
}
// Check the distance to the nearest enemy.
// If it comes closer than 10 meters, cleave it!
// Else, attack the "Chest" by name.
}
loop {
enemy = this.findNearestEnemy();
var distance = this.distanceTo("Chest"); // That is not enemy
if (distance < 10) {
if ( this.isReady("cleave")) {
this.cleave(enemy);
} else {
this.attack(enemy);
}
if (enemy) { // This is not chest
this.attack("Chest");
}
}
// Check the distance to the nearest enemy. // as per this comment
// If it comes closer than 10 meters, cleave it!
// Else, attack the "Chest" by name.
}
Ok, I’m with JFBM ugly indent makes ugly code (heck, I don’t like the so called one-true-brace) (I love python indenting, what is in is in and nothing hanging where it shouldn’t be)
Wow, now that I fixed the indent I see that the if enemy – atack chest is inside the if chest < 10 away.