Hi there! help me with the level please. I figured that my variable doesn’t update for some reason. I don’t understand why. I want the hero to spot the nearest coin, determine if its worth is > 1, and if so, pick it up. If not, get the next coin. After my hero picks up a good coin, he continues to think that the nearest and worthy coin is the one he has already picked up. The “nearest” variable doesn’t update. Here’s my code. Thanks to everyone in advance.
while (hero.time < 20) {
var coins = hero.findItems();
var coinIndex = 0;
if (coins) {
while (coinIndex < coins.length) {
var nearest = hero.findNearest(coins);
hero.say(nearest);
if (nearest && nearest.value > 1) {
while (hero.distanceTo(nearest) > 1) {
hero.move(nearest.pos);
}
} else {
break;
}
nearest = null;
coinIndex++;
}
}
}