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.
Can you at least try to write a code and send it to us to help. At least try to think at a code.
ok, i’ll try (20 chars)
@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)
Try to put that after this:
Does it work now?
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)
Put
After
Does it work now?
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)
Can you send me a link to the level?
sure.
https://codecombat.com/play/level/golden-mirage?
there you go
Delete that.
Here put
fakeCoin[fakeCoinIndex]
Does it work now?
on which line and where, @AnSeDra?
Here.(20 characters)
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)
Here put
fakeCoinIndex-=1
it says that on this line
it can’t read property ‘0’ of Null.
why?
this one (20 characters)
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?
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)