So I’m stuck on Cursed Valley, and for some reason my hero isn’t moving to any potions so when it gets to that line nothing else happens! What’s wrong with my code?!
while (true) {
var enemy = hero.findNearestEnemy();
// Attack if enemy exists AND enemy.team is "ogres"
// AND enemy.type is "skeleton"
if (enemy && enemy.team === "ogres" && enemy.type === "skeleton") {
hero.attack(enemy);
}
// Collect if item exists AND item.type is "potion"
// AND hero.health is less than hero.maxHealth / 4
if (item && item.type === "potion" && hero.maxHealth < hero.maxHealth / 4) {
var item = hero.findNearestItem();
hero.moveXY(item.pos.x, item.pos.y);
}
I tried adding that but my character stays in place!
new code:
// The hot sun is draining the hero’s health!
while (true) {
var enemy = hero.findNearestEnemy();
// Attack if enemy exists AND enemy.team is "ogres"
// AND enemy.type is "skeleton"
if (enemy && enemy.team === "ogres" && enemy.type === "skeleton") {
hero.attack(enemy);
}
var item = hero.findNearestItem();
// Collect if item exists AND item.type is "potion"
// AND hero.health is less than hero.maxHealth / 4
if (item && item.type === "potion" && hero.maxHealth < hero.maxHealth / 4) {
var item = hero.findNearestItem();
hero.moveXY(item.pos.x, item.pos.y);
}