I’ve been stuck on this level for a day and I don’t know how to solve it. Here is my code.
while True:
enemies = hero.findEnemies()
# enemyIndex is used to iterate the enemies array.
enemyIndex = 0
# While enemyIndex is less than len(enemies)
while enemyIndex < len(enemies):
# Attack the enemy at enemyIndex
enemy = enemies[enemyIndex]
hero.attack(enemy)
# Increase enemyIndex by one.
enemyIndex += 1
coins = hero.findItems()
# coinIndex is used to iterate the coins array.
coinIndex = 0
while coinIndex < len(coins):
# Get a coin from the coins array using coinIndex
coins = hero.findNearestItem()
coin = coins[coinIndex]
# Collect that coin.
hero.moveXY(coin.pos.x, coin.pos.y)
# Increase coinIndex by one.
coinIndex += 1
This code works for me, I used Anya with obsidian armour and claymore, because that’s what I had at the time. What equipment are you using? @xython I don’t see any problem?
Use the other one, since @xython managed to beat this level with the simple one, the other sword should do just fine, since you also have great amounts of HP. I haven’t gotten on codecombat in a while, so I forgot the name of the sword. Try using the sword with a short blade.
@ Sharknado - I passed the level with the sword and armor on my picture - did you try to correct your code?
@ Chaboi_3000
There are 2 problems with the default code:
#1
while enemyIndex < len(enemies):
# Attack the enemy at enemyIndex
enemy = enemies[enemyIndex]
hero.attack(enemy)
# Increase enemyIndex by one.
# Why increasing the index if you are not sure the enemy is dead
enemyIndex += 1
while coinIndex < len(coins):
# an so on
You start to collect coins but are you sure there are no enemies? They can chase you an hit you in the back
He needs no better armor or sword - only to put a line of extra code.
Sometimes, code isn’t just what they give you, sometimes you have to manipulate and shift and change the code a bit, until you get the code that’s working for you, and yes, there’s some errors in codecombat that isn’t fixed yet, and sometimes, you’ll have to deal with it, and fix it yourself! Equipment is just to make the game easier. Nick managed to do great with his Tharin against many opponents, So if you try, you can do anything with code.