[SOLVED] Bank Raid Help?

hero is my code

# Wait for ogres, defeat them and collect gold.

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.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Increase coinIndex by one.
        coinIndex += 1
there you go
# Wait for ogres, defeat them and collect gold.

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

I tried to fix it but it said X is not defined

You are defining a single item variable incorrectly as a list, not as a single object on that list. coinIndex is just the current count of the arrray of coins. Look at the line defining enemy above. It defines a single enemy object from the list of the array of enemies. You should be doing the same thing when defining a single coin.

solved it & thanks

[en_US.composer.my_button_text]

I found out that you cannot equip thornprick as it would kill the enemies without increasing the value of enemies killed

2 Likes

help says x not defined

Wait for ogres, defeat them and collect gold.

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.
itemIndex = 0
while itemIndex < len(coins):
items = hero.findNearestItem()
# Get a coin from the coins array using coinIndex
item = itemIndex
# Collect that coin.
hero.moveXY(item.pos.x, item.pos.y)
# Increase coinIndex by one.
itemIndex += 1

Please create a new topic for your problem @Timofey_Klimenko as this topic is dead, and don’t forget to format your code properly as it will be harder to help :slight_smile:

You can click this button to paste the code inside it: