I have checked back and forth my code but I could not find the problem with my loop. It kept saying unreachable ‘while’ after ‘return’.
Here is my code:
loop {
var flag = this.findFlag();
var enemy = this.findNearestEnemy();
var item = this.findNearestItem();
if (flag) {
this.cleave();// What happens when I find a flag?
this.pickUpFlag();
}
else if (enemy) {
this.attack(enemy);// What happens when I find an enemy?
}
else if (item){
var pos = item.pos;
var itemx = pos.x;
var itemy = pos.y;
this.moveXY(itemx, itemy);// What happens when I find an item?
}
}