Hello everyone. Im stuck in this level. When I run it my character just attacks the first oggres’ group and then start moving around without an apparent logic reason and doesn’t even recognize the flags… I’ve been reading again and again the code trying to find an error and I don’t know what more to do. Please somebody help me!!! The code is the next one
while(true) {
var flag = hero.findFlag();
var enemy = hero.findNearestEnemy();
var item = hero.findNearestItem();
if (flag) {
// What happens when I find a flag?
hero.pickUpFlag(flag);
}
else if (enemy) {
// What happens when I find an enemy?
var distance = hero.distanceTo(enemy);
if (distance < 5) {
if (hero.isReady("cleave")) {
hero.cleave(enemy);
}
else {
hero.attack(enemy);
}
}
}
else if (item) {
// What happens when I find an item?
var itemPos = item.pos;
var itemX = itemPos.x;
var itemY = itemPos.y;
hero.moveXY(itemY, itemX);
}
}
thanksss!