[SOLVED] Help with golden mirage please

can someone help me? i don’t know how to sort through fake and real coins. i haven’t posted code because i don’t know what code to have. thanks.

1 Like

Can you at least try to write a code and send it to us to help. At least try to think at a code.

1 Like

ok, i’ll try (20 chars)

1 Like

@AnSeDra, here’s my code, but he does’t move.

while True:
    coins = hero.findItems()
    coinIndex = 0
    coin = coins[coinIndex]
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < coins.len:
        if coin.value !=  newCoin.value:
            newCoin = coin
        else:
            fakeCoin[fakeCoinIndex] = coin
            fakeCoinIndex += 1
    fakeCoinIndex = 0
    if  (fakeCoin and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
        realCoin = newCoin
    else:
        fakeCoinIndex += 1
    if realCoin:
        hero.move(realCoin.pos)

1 Like

Try to put that after this:

Does it work now?

1 Like

i changed it a bit @AnSeDra, but it still gives the same result…
here’s the code

while True:
    coins = hero.findItems()
    coinIndex = 0
    coin = coins[coinIndex]
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    fakeCoinIndex = 0
    if  (fakeCoin and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
        realCoin = newCoin
    else:
        fakeCoinIndex += 1
    if realCoin:
        hero.move(realCoin.pos)
1 Like

Put

After

Does it work now?

1 Like

here’s the code @AnSeDra:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    fakeCoinIndex = 0
    if  (fakeCoin and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
        realCoin = newCoin
    else:
        fakeCoinIndex += 1
    if realCoin:
        hero.move(realCoin.pos)
1 Like

Can you send me a link to the level?

1 Like

sure.
https://codecombat.com/play/level/golden-mirage?
there you go

1 Like

Delete that.

Here put

fakeCoin[fakeCoinIndex]

Does it work now?

1 Like

on which line and where, @AnSeDra?

1 Like

Here.(20 characters)

1 Like

here’s the new code @AnSeDra:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    if  (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
        realCoin = newCoin
    else:
        fakeCoinIndex += 1
    if realCoin:
        hero.move(realCoin.pos)
1 Like

Here put
fakeCoinIndex-=1

1 Like

it says that on this line

it can’t read property ‘0’ of Null.
why?

1 Like

this one (20 characters)

1 Like

it says this:

1 Like

Instead of all of this, put

k=0
while k==0 and fakecoin[fakeCoinIndex]:
    if (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]): 
        realCoin = newCoin 
        k=1
    else: 
        fakeCoinIndex -= 1

Does it work now?

1 Like

it still has the same error, and here’s the code:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
    while k == 0:
        if  (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
            realCoin = newCoin
            k = 1
        else:
            fakeCoinIndex -= 1
    if realCoin:
        hero.move(realCoin.pos)
1 Like