while True:
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
coins = hero.findItems()
coinIndex = 0
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.move(coin.pos.x, coin.pos.y)
coinIndex = coinIndex + 1
````enemies = hero.findEnemies()
````enemyIndex = 0
````while enemyIndex < len(enemies):
````enemy = enemies[enemyIndex]
````hero.attack(enemy)
````enemyIndex += 1
````coins = hero.findItems()
````coinIndex = 0
````while coinIndex < len(coins):
````coin = coins[coinIndex]
````hero.move(coin.pos.x, coin.pos.y)
````coinIndex = coinIndex + 1
tried to format it, i am sorry if this doesn’t work.
there is a while loop at the top even though it doesn’t show.
Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!
Could you repost your code? I have a feeling you did it incorrectly… All you need to do is simply press the </> button and paste your code in it.
Are you supposed to be doing findNearestEnemy or just findEnemy?
while True:
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
coins = hero.findItems()
coinIndex = 0
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.move(coin.pos.x, coin.pos.y)
coinIndex = coinIndex + 1
Formatted it correctly
Use moveXY
. (20)
You can replace while enemyIndex < len(enemies):
to for enemy in enemies:
and do the same for the coins it will reduce the code so you only would have to write 7 lines of code
or hero.move(coin.pos)
Let me try… (20chars)
So, the problem with using move
is because it will move you slightly in the direction of the given object - the coin - but not move you to it completely and your hero will just be moving around in circles… moveXY
takes you to it and will follow through with the movement until it is done. Just use moveXY and move will come up in the mountain. @hellodaddy you should change this:
Ok my bad(2000000000)
while True:
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
items = hero.findItems()
itemIndex = 0
while itemIndex < len(items):
item = items[itemIndex]
hero.move(item.pos.x, item.pos.y)
itemIndex = itemIndex + 1
while True:
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
items = hero.findItems()
itemIndex = 0
while itemIndex < len(items):
item = items[itemIndex]
hero.moveXY(item.pos.x, item.pos.y)
itemIndex = itemIndex + 1
while True:
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
items = hero.findItems()
itemIndex = 0
while itemIndex < len(items):
item = items[itemIndex]
hero.moveXY(item.pos.x, item.pos.y)
itemIndex = itemIndex + 1
Thx a lot. I have been working on this for so long. For the hero.move thing I was typing hero.m then pressing the down arrow then enter. I think that messed it up a little bit somehow.
my code will have the hero attack two waves of enemies and one wave of coins. Can you pls tell me why?
Never mind. For some reason when I had a ring of thorns on it bugged it and made it not work. But it works now. Thx a ton guys.
Sorry I couldn’t answer. I have been extremely busy this weekend.