Can't beat level 10

it keeps saying

“Line 9: Target is null. Is there always a target to attack? (Use if?)”

I can’t beat it

You should give more information than ‘level 10’, the levels aren’t entirely linear, so ‘level 10’ doesn’t tell us anything. Give the name of the level. You should also post your actual code, using the formatting instructions found here:

The error alone won’t always be enough information for someone to help you. In fact I don’t even know what language you are using, but I will assume that you are using Python since that is the default.

Now as to your problem, the error you are getting is telling you that you are specifying a target which may be null (it may not exist), and you need to use a conditional statement to check to see if it exists before you try to do something with it.

So instead of:

target = self.findNearestEnemy()


target = self.findNearestEnemy()
if target:

The same holds true any time you pass an object as a parameter, or access members of an object. Always check to make sure the object exists.

1 Like