I am typing this into the box above Run:
Remember that enemies may not yet exist.
loop:
enemy = self.findNearestEnemy()
# If there is an enemy, attack it!
self.attack(self.findNearestEnemy())
It isn’t working, and I was wondering what was wrong. It keeps giving me
Fix Your Code:
Line five: Target is null, is there always a target to attack?
Is there anything I can do? I’m running it in Python
Vettax
2
Sorry, I don’t know the syntax in Python.
But you need to test if enemy exist before attacking them.
Something like:
enemy = self.findNearestEnemy()
# If there is an enemy, attack it!
if (enemy)
self.attack(enemy)
in fact, you just do exactly what was requested in the comment…
if (enemy) is equivalent to if(enemy!=null)
3 Likes
Also thanks you help me a LOT!!!
I need help with that level too but im using JavaScript, I’ve tried a lot of things but it doesn’t work! can some1 help me please??