if flag:
# What happens when I find a flag?
self.pickUpFlag(flag)
elif enemy:
# What happens when I find an enemy?
if self.isReady(“cleave”) and self.distanceTo(enemy) <5:
self.cleave(enemy)
elif:
self.attack(enemy)
elif item:
# What happens when I find an item?
pos = item.pos
x = pos.x
y = pos.y
this.pickUpFlag(flag);
}
else if (enemy) {
// What happens when I find an enemy?
this.attack(enemy);
this.attack(enemy);
}
else if (item) {
// What happens when I find an item?
var fx = pos.x;
var fy = pos.y;
this.moveXY(pos.x, pos.y);
}
}
Pls help. IDK how to fix this. My code is below: (Javascript)
// Use "if" and "else if" to handle any situation.
// Put it all together to defeat enemies and pick up coins!
// Make sure you bought great armor from the item shop! 400 health recommended.
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(a); // <-- The "a"
} else if (enemy) {
// What happens when I find an enemy?
while (true) { // Do I need the while-true loop?
hero.attack(enemy);
}
} else if (item) {
// What happens when I find an item?
var posItem = pos.item;
var fx = posItem.x;
var fy = posItem.y;
}
}