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

Shine Getter help(The First user's problem is SOLVED. The second user who is experiencing issues needs help)

Can someone help me with my code, please?

# To grab the most gold quickly, just go after gold coins.

while True:
    coins = hero.findItems()
    coinIndex = 0
    
    # Wrap this into a loop that iterates over all coins.
    while coinIndex < len(coins):
        
        # Gold coins are worth 3.
        if coins.value == 3:
            # Only pick up gold coins.
            hero.moveXY(coins.pos.x, coins.pos.y)
        coinIndex += 1
    pass
        

hero won’t move

coins is defined as an array, not a single item, so there is no single position to move to. You have to define coin and then move to the coin.pos.

Can you show me how to do that?

coin = coins[coinIndex]

Remember this chunk of code. You’re going to be seeing this format a LOT.

Like this

while True:
    coins = hero.findItems()
    coinIndex = 0
    
    # Wrap this into a loop that iterates over all coins.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        # Gold coins are worth 3.
        if coins.value == 3:
            # Only pick up gold coins.
            hero.moveXY(coins.pos.x, coins.pos.y)
        coinIndex += 1
    pass

you still didn’t change the places where you refer to coins instead of coin.

like this

while True:
    coins = hero.findItems()
    coinIndex = 0
    
    # Wrap this into a loop that iterates over all coins.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        # Gold coins are worth 3.
        if coins.value == 3:
            # Only pick up gold coins.
            hero.moveXY(coin.pos.x, coin.pos.y)
        coinIndex += 1
    pass

I figured it out now

Mod edit: Please do not post for assistance in multiple locations for the same issue. You will not receive assistance faster with multiple posts.

can someone help me with this code:

while True:
coins = hero.findItems()
coinIndex = 0

# Wrap this into a loop that iterates over all coins.
while coinIndex < len(coins):
    coin = coins[coinIndex]
    # Gold coins are worth 3.
    if coins.value == 3:
        # Only pick up gold coins.
        hero.moveXY(coin.pos.x, coin.pos.y)
    coinIndex += 1
pass

my hero will not move

You define the variable, coin, but don’t use it. Coins is plural. Coins cannot have a value equal to 3 because coins is an array. Look closely at what you’ve written. :wink: