[SOLVED] Bank raid help me

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]
        # 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
        coinIndex = 1
        # Collect that coin.
        item = hero.findNearestItem()
        coin = coin[coinIndex]
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Increase coinIndex by one.
        coinIndex +=1

it says on coin = coin [coinIndex] can not read the property of 1

What is this line:

doing to this line?

Which coin are you finding each loop?

He, I forgot everything about Index.

Hi @avery_witte, there are a couple issues with your code. The first issue with your code is this i’m pretty sure:

This is wrong because every time you go through the loop it is going to reset coinIndex back to 1.
You should actually set coinIndex to 0 above the while loop.

The next thing is this:

It should be like this:

coin = coins[coinIndex]

This is because you want to iterate through all the coins.
Hope this helps!

1 Like

I should be

coinIndex += 1

you need to add the + sign in. Then, it increments the index + 1 every time.

1 Like

At the end you need to increment it, but I was talking about the starting value. You need to set it to 0


Oh…I missed that she did the increment thing. :grimacing: :grimacing:

1 Like

thanks I figured it out I forgot to put a brake with the code so it makes sure the character actually collects the coins and attacks the enemies

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.