same thing same thing
also it here is the code
# Wait for ogres, defeat them and collect gold.
while True:
enemies = hero.findEnemies()
# enemyIndex is used to iterate the enemies array.
itemindex = 0
enemyIndex = 0
coinIndex = 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.
items = hero.findItem
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.moveXY(coin.pos.x, coin.pos.y)
Try moving this
and
to the while loop
The problem is you are not doing the same thing for the coins, you have to increment coinIndex, otherwise it will be stuck in an infinite loop and will definitely lag
And this is unnecessary, you should remove it.
along with this
Do you have the ring of thorns on? It is a little known bug where on bank raid the ring of thorns bugs the level. There still could be smth wrong with your code though, just take the ring of thorns off.
It helps to mentally break this down by steps.
1 )First, you see enemies and beat them up, using a while-loop. It sounds like this part works.
2)Then you find the coins and move to them to pick them up in its own while-loop. (which isn’t working)
3)Then you are supposed to repeat steps 1 & 2, but since you don’t finish 2, you never get to this part.
So looking at step 2, you need to identify the coins/items array, declare the index, and loop through. Coins are a type of item (and in this level there are no other types like potions). So you find them with array = hero.findItems()
You only need to do that in one way, choose either coins = hero.findItems() or items = hero.findItems(). (You should delete the items one, you have a typo there anyways. Which means you should also remove itemIndex = 0, because it is just cluttering up your code and making it more confusing.)
So once you’ve cleaned out the extra, your code will look this this (except for the comments I added to help you):
while True:
enemies = hero.findEnemies()
enemyIndex = 0
coinIndex = 0 # coinIndex works fine here, or move it to just before the coin loop for clarity
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
# added space is optional, for ease of reading
coins = hero.findItems()
# <--could move coinIndex definition here for clarity
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.moveXY(coin.pos.x, coin.pos.y)
# Isn't something missing here? (Increment coinIndex within the loop aka coinIndex += 1)
# If you move coinIndex down to spot indicated, and made a habit of it, it will be easier to
# see and remember if you have all the necessary parts in your loop.
# Later on, if you want all the variables at the top, you can move them once everything works.
You second while-loop (for coins) never increments, so it becomes and infinite loop and breaks your program.
Here is a template that shows a similar idea, so you can see the simpler layout.
while True:
monsters = hero.findMonsters() #(not a real method, just an example)
monsterIndex = 0
while monsterIndex < len(monsters):
myMonster = monsters[monsterIndex]
hero.attack(myMonster)
monsterIndex += 1
collectibles = hero.findStuffWeWant() #(also a fake method)
collectibleIndex = 0
while collectibleIndex < len(collectibles):
myNewFavoriteThing = collectibles[collectibleIndex]
hero.moveXY( myNewFavoriteThing's location)
collectibleIndex += 1
# a generic layout example, helps you remember each step:
array = method creating array
arrayIndex = 0
while arrayIndex < len(array):
thingInsideArray = array[arrayIndex]
instructions for thingInsideArray
arrayIndex += 1
I hope this is clear and helps you.
thanks here is my text
while True:
enemies = hero.findEnemies()
enemyIndex = 0
coinIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
coins = hero.findItems()
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.moveXY(coin.pos.x, coin.pos.y)
but it only picks up 1 coin
no i dont have it. but thank you for the sugestion
mow it doesnt collect
i modified it
while True:
enemies = hero.findEnemies()
enemyIndex = 0
coinIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
hero.attack(enemy)
enemyIndex += 1
coins = hero.findItems()
while coinIndex < len(coins):
coin = coins[coinIndex]
hero.moveXY(coin.pos.x, coin.pos.y)
coinIndex += 1
You need to check your indents again. Everything needs to be within the while True. Your coin loop needs some adjustment.
ok thank you helped me
i finished it here it is
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.moveXY(coin.pos.x, coin.pos.y)
coinIndex = coinIndex + 1
Terrific! Does it work now, then? If so, you should mark this as “solved”.