// Coins here disappear after a few seconds!
// Get all the gold coins before they vanish.
while(true) {
var closestGold = null;
var minGoldDist = Infinity;
var coinIndex = 0;
var coins = hero.findItems();
// Find the closest coin that is gold.
// Remember that gold coins have a value of 3.
if (coins.value > 2) {
hero.moveXY(coins.pos.x,coins.pos.y);
}
if(closestGold) {
// Now go to the closest gold coin and get it!
hero.moveXY(closestGold.pos.x,closestGold.pos.y);
}
}
Here try to loop over all the coins and find out the hero.distanceTo(coin) and if coin.value == 3 and distance < minGoldDist, then update the minGoldDist to distance and update the closestGold to coin.
Andrei
Please just help in one for now. I have to move through everything looking at what you just typed.
Do you understand what I told you there or not?
Nope I do not understand
Here put
while (coinIndex < coins.length){
var coin = coins[coinIndex];
var distance = hero.distanceTo(coin);
if (coin.value == 3 && distance < minGoldDist){
//here make closestCoin to be coin
//here make minGoldDist to be distance
pass;
}
}
Andrei
wait a sec let me finish sarven siege
Try to focus at only one level at a time.
Andrei
Ok. So, no multitasking.
Yes. Because you should complete a level and after that try another one.
Andrei
Ithink my computer is gonna crash
@Monsty can you show your new code please?
my code:
return; //Commented out to stop infinite loop.
// Coins here disappear after a few seconds!
// Get all the gold coins before they vanish.
while(true) {
var closestGold = null;
var minGoldDist = Infinity;
var coinIndex = 0;
var coins = hero.findItems();
// Find the closest coin that is gold.
// Remember that gold coins have a value of 3.
while (coinIndex < coins.length){
var coin = coins[coinIndex];
var distance = hero.distanceTo(coin);
if (coin.value == 3 && distance < minGoldDist){
//here make closestCoin to be coin
//here make minGoldDist to be distance
pass;
}
}
if(closestGold) {
// Now go to the closest gold coin and get it!
hero.moveXY(closestGold.pos.x,closestGold.pos.y);
}
}
what’s this about???
there was an infinite loop and you can’t go back into an infinite looped level
here you need to do what’s in the comments
After this put coinIndex++; so you won’t have an infinity loop.
Andrei
I reset all my code but it won’t let me in
What I told him to do in the comments.
Andrei