I’m in the level “Sarven Brawl” in the Sarven Desert.
This is part of my code… :
while True:
enemiesInSight = hero.findEnemies()
for n in enemiesInSight:
if isPartOf(enemiesInSight[n], doNotAttack) == True:
break
nDistance = hero.distanceTo(enemiesInSight[n].pos)
if n < 1 :
nearestEnemy = enemiesInSight[n]
else:
if nDistance < hero.distanceTo(nearestEnemy):
nearestEnemy = enemiesInSight[n]
enemy = nearestEnemy
EDIT: more info
It seems what the rubber duck says at the end of the error message (in the case of my screenshot, Vyle, but i’ve also seen Polyfemo once) is the name of… an enemy… I think
So, does that mean the method hero.findEnemies() which should return a whole array of enemies only returns one, which turns into the wrong type of variable… which is a problem ?
What do you think ?
Please give more information about what is happening, what level you are on, which world you are in? Any additional information would be extremely helpful.
I’m on the Sarven Brawl level, in Sarven Desert.
The part that was highlighted (in yellow or green, i can’t say) was the line that goes enemiesInSight = hero.findEnemies().
Also, this is only part of my code for this level, i may add more if anyone thinks it might be interesting.
And i don’t know what more to say, because i don’t know what might be the source of the problem
It will not work, because the point of the for loop after enemiesInSight = hero.findEnemies() is to sort through the newly stored array and find the nearest enemy that is not part of my custom array named doNotAttack.
Your solution will only find the nearest enemy, regardless if it’s part of the doNotAttack array
No, I haven’t solved the problem, the method isPartOf() works, but what seems to not work is this specific line of code : enemiesInSight = hero.findEnemies()
It seems what the rubber duck says at the end of the error message (in the case of my screenshot, Vyle, but i’ve also seen Polyfemo once) is the name of… an enemy… I think
So, does that mean the method hero.findEnemies() which should return a whole array of enemies only returns one, which turns into the wrong type of variable… which is a problem ?
What do you think ?
Ok now the game threw me an error for a line of code i didn’t even write and which was in this exercise even before i started typing. Is it a bug now ?
The name of the exercise in english is “Fair Battle” in the Sarven Desert.
for enemy in enemies:
hero.attack(enemy) # this is right
##############################
for enemy in enemies:
hero.attack(enemies[enemy]) # and this is wrong
In your code n isn’t an index, but an object ( enemy or friend ) so the message is appropriate. Same error is displayed in Mad Maxer strikes back topic. where an object is put into the while loop.
Ah, thank you so much i couldn’t get my head around the problem , so much i thought it was a bug
I often forget the sole name of the object isn’t enough to get its properties, or that that the code needs a particular input. For example i’ve often times written hero.moveXY(coin) or even hero.moveXY(coin.pos).
Is it possible to simply get the index of any entry in an array ? something that would read like units[n].index ?