pls help,I couldn’t figure out.
always get line 8:type error: statement execution limit reached
what’s the issue here?
while(true) {
var coins = hero.findItems();
var coinIndex = 0;
// Wrap this into a loop that iterates over all coins.
while(coinIndex < coins.length) {
var coin = coins[coinIndex];
// Gold coins are worth 3.
if (coin.value == 3) {
// Only pick up gold coins.
hero.moveXY(coins.pos.x, coins.pos.y);
coinIndex += 1;
}
}
}
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!
Statement execution limit usually means something is stuck in an infinite loop. In this case, it’s your loop going across all coins.
Think carefully about what happens if it’s currently inspecting, say, a silver coin (coin.value == 2). Since the if statement isn’t run, coinIndex is never incremented, and the loop will run again inspecting the same coin. Repeat forever.
To solve this you’ll want to move coinIndex += 1 out of the if statement. Regardless of whether the coin is a gold coin or not, you don’t want to handle it again, so increment to the next one.