Shine Getter Help Please

What is wrong with this code?

# 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.
    if coinIndex < len(coins):
        coin = coins[coinIndex]
    # Gold coins are worth 3.
    if coin.value == 3:
        # Only pick up gold coins.
        hero.moveXY(coin.pos.x, coin.pos.y)
    coinIndex += 1
    pass

You might want to use preformatted text so the Community can help you.


When posting a new topic for level help
Use this to make it easier for the community
Then, copy and paste your code, and then your good

2 Likes

Do you mind sending me the link to your level?
Once you do I can see what is wrong with your code
But if this is your actual code then you need indentation.

1 Like

Changed to add preformatted code!

1 Like

You can also guess the url of the level sometimes
this one is CodeCombat - Coding games to learn Python and JavaScript
as you can see, the level name “shine getter” gets turned into “shine-getter” in the url

this part needs to be a loop of some kind and not a if-statement (whether it be a for loop or a while loop)
otherwise, the code will only execute once and then coinIndex will be reset and it will keep checking the same coin repeatedly
if this is also your indentation, you may need to indent the

so that it is inside the new loop that you just created
(this level is a bit annoying for that; it kinda mentions indenting but doesn’t make it clear)

1 Like

So how do I help someone on a level I know the answer to? However I know what’s wrong with the code but I don’t know how to tell him to fix it without giving him the answer because he’s so close to getting it.

1 Like

I think telling someone what to do (but not giving code) and more importantly, why their code wasn’t working / why the new code would work is fitting

1 Like

ok so like if his is code is only running one time but I say I think you should maybe loop you code so the code can do it over again or do I say maybe you should think what do I need to make my code run the code over and over again?

I think the first is right for this situation (which is what I did)
depends on the level; by this desert level (almost at the end) you should know how while loops work

1 Like

Is it fine if I go ahead and say what he could do to change/improve you code

yeah I think so
just not any complete code

1 Like

A way to improve his code I would think would be the If/else statement that is causing the game to only run one code, which in this case he would need to change and probably use the while loop statement so it runs the other codes too, then it would break the infinite loop and then he’s good. @JustALuke does this sound like good help or is this like giving out the answer? which would be right here
if coinIndex < len(coins):

1 Like

yeah that’s good help
just telling someone how to fix it

1 Like

K cool I was just making sure because I’ve already done my research in posts, and it says not to just give them the answer even though I kinda did but however, also they kinda do get to experiment with it themselves.

1 Like