[SOLVED] Need help with Bank Raid

// Wait for ogres, defeat them and collect gold.
while (true) {
    var enemies = hero.findEnemies();
    // enemyIndex is used to iterate the enemies array.
    var enemyIndex = 0;
    // While enemyIndex is less than enemies.length
    while (enemyIndex < enemies.length) {
        // Attack the enemy at enemyIndex
        var enemy = enemies[enemyIndex];
        hero.attack(enemy);
        // Increase enemyIndex by one.
        enemyIndex++;
    }
    var coins = hero.findItems();
    // coinIndex is used to iterate the coins array.
    var coinIndex = 0;
    while (coinIndex < coins.length) {
        // Get a coin from the coins array using coinIndex
        var coins = hero.findNearestItem();
        var coin = coins[coinIndex];
        // Collect that coin.
        hero.moveXY(coins.pos.x, coins.pos.y);
    
    // Increase coinIndex by one.
    coinIndex++;
}
}

The hero would stay in one position and not move to get the coins

Howdy and welcome to the forum!

The problem is in your final line of code…’++’ is a ‘C’ method, not (I’m pretty sure) a JS one. Change this line to the proper method and your code will work fine.

@rapwrap the problem with your code is when you repeat var coins. You don’t need the second var coins line

your code should work if you remove that line

@Falcons118 try running his code with the correction I suggested…it succeeds with no other changes.

hello guys. yeah it woks

I tried it in java too

1 Like

oh, but I have almost similar code to him and I removed his second var coins line and it also worked

Did you use the C method of ‘++’ to increment your counter?

For my last line of code i wrote CoinIndex++

And I finished the level a long time ago

@rapwrap did you solve the level

1 Like

heh…that’s interesting. I just pasted his code back in, unchanged, and ran it…it passed. :grin:

Lol. Does the equipment affect anything in this level?

That’s where I’m leaning, but he does state that:

I guess we should give him a chance to catch up and respond himself. :wink:

That’s what I am trying to say

Yea i solved the level thank you for your help

1 Like

@dedreous when he puts find nearest items for var coins the hero doesn’t move. I tried his code and it didn’t work. @rapwrap try to remove the line where you restate var coins= hero.findNearesItems

Click the solved button on whichever comment helped you sol that others will know that this topic is solved

All I can say is that his unchanged code runs perfectly…notice the ‘unpretty’ formatting is retained; it’s his code: