# \[SOLVED\] Bank Raid Help?

**URL:** <https://discourse.codecombat.com/t/solved-bank-raid-help/16009>\
**Category:** Solved\
**Created:** [September 22, 2018, 1:20pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009 "2018-09-22T13:20:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 1:20pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/1 "2018-09-22T13:20:02Z")

</div>

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

```python
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

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [September 22, 2018, 2:11pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/2 "2018-09-22T14:11:05Z")

</div>

It’s because you’ve said

> [@Sharknado](#):
>
> coins = hero.findNearestItem()

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.

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 2:37pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/3 "2018-09-22T14:37:10Z")

</div>

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

```python
Fixed code seems to be working so removed by mod

```

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [September 22, 2018, 4:11pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/4 "2018-09-22T16:11:33Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [September 22, 2018, 5:22pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/5 "2018-09-22T17:22:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [September 22, 2018, 5:35pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/6 "2018-09-22T17:35:25Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/30ec0b3ba434c67c7882c06aef7a540f64655541.jpeg)

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…

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 6:38pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/7 "2018-09-22T18:38:10Z")

</div>

This is my equipment  
 ![42](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/cf3ae6caba3c5078314d9c234f0d53292ddc396c.png)

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [September 22, 2018, 9:14pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/8 "2018-09-22T21:14:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 9:28pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/9 "2018-09-22T21:28:45Z")

</div>

I only have 47 gems.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [September 22, 2018, 9:31pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/10 "2018-09-22T21:31:30Z")

</div>

Can I see the list of swords you currently have?

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 9:36pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/11 "2018-09-22T21:36:02Z")

</div>

Hero you go  
 ![25](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/c422646ec0d4e26c6fe40d794c1f96ccd81ac4ba.png)

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [September 22, 2018, 9:37pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/12 "2018-09-22T21:37:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 9:41pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/13 "2018-09-22T21:41:40Z")

</div>

The sharped sword did not work at all. ☹

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [September 22, 2018, 9:42pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/14 "2018-09-22T21:42:13Z")

</div>

@ 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:

```python
#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

```

```python
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.

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 22, 2018, 9:44pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/15 "2018-09-22T21:44:29Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [September 22, 2018, 9:46pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/16 "2018-09-22T21:46:16Z")

</div>

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. 😉

---

<div class="post-metadata">

**Author:** ![VanPham](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vanpham/32/10135_2.png) [@VanPham](https://discourse.codecombat.com/u/VanPham)\
**Post date:** [April 24, 2019, 4:21am UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/22 "2019-04-24T04:21:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Osborne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_osborne/32/10772_2.png) [@Michael\_Osborne](https://discourse.codecombat.com/u/Michael_Osborne)\
**Post date:** [August 30, 2019, 7:37pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/23 "2019-08-30T19:37:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 30, 2019, 10:09pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/24 "2019-08-30T22:09:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Osborne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_osborne/32/10772_2.png) [@Michael\_Osborne](https://discourse.codecombat.com/u/Michael_Osborne)\
**Post date:** [September 16, 2019, 7:38pm UTC](https://discourse.codecombat.com/t/solved-bank-raid-help/16009/25 "2019-09-16T19:38:57Z")

</div>

I do not know

[en\_US.composer.my\_button\_text]

[Next page](https://discourse.codecombat.com/t/solved-bank-raid-help/16009.md?page=2)
