Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Bank raid help me!

I need help!

After my hero is done collecting coins at first, it defeats its second enemies, it stops. 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
        coin = coinIndex
        # Collect that coin.
        item = hero.findNearestItem()
        hero.moveXY(item.pos.x, item.pos.y)
        # Increase coinIndex by one.
        coinIndex += 1

Please help! :smiley:

Hi! Can you provide direct level link, please?

A few details to clean up, although this didn’t directly impact the problem. What hero and gear do you have? I found that the Ring of Thorns can cause some problems on this level.

To use the index for the array it should be: variable = array[index]

    while coinIndex < len(coins):
        # Get a coin from the coins array using coinIndex
        coin = coinIndex # look at how it was done with enemy

Then use that variable for the move command instead of creating a new variable.

https://codecombat.com/play/level/bank-raid?

1 Like

image

This is my stuff.

I did it! thanks for the help

Nevermind, it stopped working

First do what Brooksy said, but even then it still doesn’t work sometimes and the hero just says “But it’s dead!”. To solve this simply put: if enemy.health > 0: before you attack the enemy to make sure it’s still alive.
-Danny

When I do that it just shows the X.

It worked! I finally finished bank raid. Thanks for the help.

1 Like