Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Agrippa Defence level in Python (Help, Please!)


Hello, everyone! Please help me fix my code for the Agrippa Defence level in Python.
I suck at coding so it’s probably a very simple beginner’s mistake I can’t spot.

Here’s what I have so far, copied and pasted -

while True:
enemy = hero.findNearestEnemy()
if enemy:
pass # Replace this with your own code.
# Find the distance to the enemy with distanceTo.
distance = hero.distanceTo(enemy)
# If the distance is less than 5 meters…
if distance < 5:
if hero.isReady(“cleave”) :
enemy = hero.findNearestEnemy()

The error message I’m getting is that the target is null on line 13. I don’t understand this as I clearly put the find nearest enemy prior to it.

Any help is appreciated, I know I’m a bit of a bimbo when it comes to this!


Since you didn’t post your code using the </> button, we can’t see the structure, but you don’t need to define enemy a second time after the else conditional. The first time inside the while True loop is sufficient for all of the code inside the loop. This looks like it could a structure problem so please copy your code from the game - not from here - and use the </> button so we help you.


Target’s null on the last line is because u didn’t check if enemy for the hero.attack(enemy) at the end of your code.


if it’s tabbed correctly, then that code doesn’t need to check for an enemy a second time. That’s why we need to see the structure.


i’m just saying that that is a possibility, and if that works, good. if it doesn’t, meh