Please, format your code correctly. There is a button for that : </> . If you don’t know how to use it, please read FAQ.
```
enemy = self.findNearestEnemy()
if enemy:
self.attack(enemy)
```
Trying to decipher what you’re trying to say and working on it. Is this you whole code up there ? Because there are several obvious reason why it’s not working.