[SOLVED] Bank Raid Help?

I’ve been stuck on this level for a day and I don’t know how to solve it. Here is my code.

while True:
    enemies = hero.findEnemies()
    # enemyIndex is used to iterate the enemies array.
    enemyIndex = 0
    # While enemyIndex is less than len(enemies)
    while enemyIndex < len(enemies):
        # Attack the enemy at enemyIndex
        enemy = enemies[enemyIndex]
        hero.attack(enemy)
        # Increase enemyIndex by one.
        enemyIndex += 1
    coins = hero.findItems()
    # coinIndex is used to iterate the coins array.
    coinIndex = 0
    while coinIndex < len(coins):
        # Get a coin from the coins array using coinIndex
        coins = hero.findNearestItem()
        coin = coins[coinIndex]
        # Collect that coin.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Increase coinIndex by one.
        coinIndex += 1

It’s because you’ve said

That doesn’t make any sense if you think about it.
And you’ve got to check if there’s a coin.
Your code is correct apart from that though.

I’ve fixed it but my hero is not collecting the coin he only attacks the enemy.

Fixed code seems to be working so removed by mod

Ugly patch to make your code working. But there is something wrong with the level default code…

        enemy = enemies[enemyIndex]
        while enemy and enemy.health > 0: # put this line 
            hero.attack(enemy)
1 Like

This code works for me, I used Anya with obsidian armour and claymore, because that’s what I had at the time. What equipment are you using?
@xython I don’t see any problem?

The armor is a little bit extreme but the level passes with the correction and fails without it. I think the default code is not the best…

This is my equipment
42

I don’t see a problem with the body armor. Try replacing the sword with another better one, because that sword is pretty slow and weak

I only have 47 gems.

Can I see the list of swords you currently have?

Hero you go
25

Use the other one, since @xython managed to beat this level with the simple one, the other sword should do just fine, since you also have great amounts of HP. I haven’t gotten on codecombat in a while, so I forgot the name of the sword. Try using the sword with a short blade.

The sharped sword did not work at all. :frowning:

@ Sharknado - I passed the level with the sword and armor on my picture - did you try to correct your code?
@ Chaboi_3000
There are 2 problems with the default code:

#1
    while enemyIndex < len(enemies):
        # Attack the enemy at enemyIndex
        enemy = enemies[enemyIndex]
        hero.attack(enemy)
        # Increase enemyIndex by one. 

        # Why increasing the index if you are not sure the enemy is dead

        enemyIndex += 1
while coinIndex < len(coins): 
# an so on

You start to collect coins but are you sure there are no enemies? They can chase you an hit you in the back
He needs no better armor or sword - only to put a line of extra code.

1 Like

@xython I did use the armor that you used and the sword but it attacked the enemy and stayed in the same spot to attack the enemy

Sometimes, code isn’t just what they give you, sometimes you have to manipulate and shift and change the code a bit, until you get the code that’s working for you, and yes, there’s some errors in codecombat that isn’t fixed yet, and sometimes, you’ll have to deal with it, and fix it yourself! Equipment is just to make the game easier. Nick managed to do great with his Tharin against many opponents, So if you try, you can do anything with code. :wink:

thank you so much, i’ve stuck in this leve for 2 days. :joy: @xython

while True:
enemies = hero.findEnemies()

enemyIndex is used to iterate the enemies array.

enemyIndex = 0

While enemyIndex is less than len(enemies)

while enemyIndex < len(enemies):

Attack the enemy at enemyIndex

enemy = enemies[enemyIndex]
hero.attack(enemy)

Increase enemyIndex by one.

enemyIndex += 1
coins = hero.findItems()

coinIndex is used to iterate the coins array.

coinIndex = 0
while coinIndex < len(coins):

Get a coin from the coins array using coinIndex

coin = coins[Index]

Collect that coin.

hero.moveXY(hero.pos.x, hero.pos.y)

Increase coinIndex by one.

coinIndex += 1
I am stuck on it too Please Help me!

When you are assigning the coin with the index, you are using a different index name than what you originally assigned.

I do not know

[en_US.composer.my_button_text]