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

[SOLVED] Shine Getter - (Level Help)

What?

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;
  while(true) {
    var coin = coins[coinIndex];
    if (coin.value == 3) {
      hero.moveXY(coin.pos.x, coin.pos.y);
    
    }
    coinIndex = coinIndex + 1;
}
}

Why does it say,
“TypeError: Cannot read property ‘value’ of undefined”?
It collects three gold coins, then just stops.

It stops because you do not go through all of the items. Try to put a

while (coinIndex< coins.length){

Instead of the second while (true).
Let me know if you need any more assistance at this level, all right?

1 Like

@mayro, for the second while loop, you need to type

while (coinIndex < coins.length)

and you need to remember to put a

coinIndex = coinIndex + 1;

or

coinIndex += 1;

at the end of the if statement.

1 Like

But he already have that. Look:

And I also told him about the while loop.
@mayro, do you need any more assistance at this level?

1 Like

i meant that after this he should have the coinIndex += 1;

That is not a problem! The things I told him are the wrong stuff.

2 Likes

ok thanks! :smile: (20 chars)

1 Like

def repeat():
while True:
coins = hero.find items
while coinIndex < len(coins)
coin = coins[coinIndex]
while True:
if coin.value == 3:
hero.moveXY(coin.pos.x, coin.pos.y)
coinIndex += 1
if hero.gold > 100:
break
else:
repeat(1)
else:
repeat()
coinIndex = 0
while True:
coins = hero.findItems
while coinIndex < len(coins)
coin = coins(coinIndex)
while True:
if coin.value == 3:
hero.moveXY(coin.pos.x, coin.pos.y)
coinIndex += 1
if hero.gold > 100
break
else:
repeat(1)
else:
repeat()
Code never finished.

Oliver, we cannot help if your code is not properly formatted. Please repost, following the direction in this topic: [Essentials] How To Post/Format Your Code Correctly

my name’s Oliver, so i was a bit confused, then i saw @Oliver_Davidson.
:rofl:

1 Like

How exactly do i do that?

Wait, i figured it out.

def repeat()
    while True:
        coins = hero.findItems
        while coinIndex < len(coins):
            coin = coins[coinIndex]
            while True:
                if coin.value == 3:
                    hero.moveXY(coin.pos.x, coin.pos.y)
                    coinIndex += 1
                    if hero.gold > 100:
                        break
                    else:
                         repeat(1)
                else:
                     repeat()
coinIndex = 0
while True:
    coins = hero.findItems
    while coinIndex < len(coins):
        coin = coins(coinIndex)
        while True:
            if coin.value == 3:
                hero.moveXY(coin.pos.x, coin.pos.y)
                coinIndex += 1
                if hero.gold > 100
                    break
                else:
                    repeat(1)
            else:
                repeat()

@Oliver_Davidson, if that’s working code, please delete it. we don’t want people to have the option to cheat at a level.

1 Like

As @ActualllOLLIEpop said, if that code can be used to complete the level, then delete from the forum so it will not be used by someone else, too.

2 Likes

As it is not a working code I will try to help you.
You do not need this while True

Or this function

Or those two else:

What you need to do is to move this

Out of the if and after this

And put this

After the line in what you find all of the items and put them in the array coins.
Do you need any more assistance at this level?

1 Like

No, it doesn’t work.

Also, I figured it out.

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