Help bank raid(help)

please help me.i cant figure it out.

please help me.i cant figure it out.

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(coins.pos.x, coins.pos.y)
# Increase coinIndex by one.
itemIndex += 1

Can you post the code correctly by putting “```” before and after it

Code will then look like this 
#It will format automatically

Instead of this

oh ok

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

sorry

"

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

You see the
image
button on your keyboard?
Press that 3 times at the start and end of your 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.
items = hero.findItems()
x = item.pos.x
y = item.pos.y
while itemIndex < len(coins):
# Get a coin from the coins array using coinIndex
item = itemIndex
# Collect that coin.
hero.moveXY(coins.pos.x, coins.pos.y)
# Increase coinIndex by one.
itemIndex += 1 ‘’’

Edit:
image
This is a speech mark, not a back tick


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

So what happens when you run the code, what’s wrong?

it doesnt pick up the coins

only kills all of them once

it says ‘‘try hero.pos’’

when i want item pos

What area is the Bank Raid level in?

desert area in desert

So I’ve replaced item.pos with hero.pos and it says this:
image
You need to define what itemIndex is
Then when the Hero knows what itemIndex is, it wil use that to find the coins and collect them

here is my code now


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