Okay dunno if this is a bug but when I use the following code:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
what happens is that my character simply keeps attacking a single enemy even when its hp has dropped to zero.
where this becomes a problem is in levels where you need to attack different enemies.
One example would be Village Rover
If I’ve simply written the code wrong then could someone tell me what I’m doing wrong?
The code is working fine for me, but it may be your indentation. Please use three backticks (or highlight the code and press the < / > button) when posting code, so that we can see your indentation. I just used this code (in Python) on Village Rover. It works fine:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
You might consider using if enemy and enemy.health > 0: instead
I see that you said “where this becomes a problem is in levels where you need to attack different enemies.” Are you saying the level that your doing now only has one enemy? If so then your code would work as long as new enemies are appearing.
sorry about not posting earlier. managed to find the problem myself and fixed it. Kinda hard to explain what the problem was but I managed to solve it.