Hi,

I need help with the Agrippa Defense. This is Python. Here is my code.

``````     loop:
enemy = self.findNearestEnemy()

if enemy:
a = self.distanceTo(enemy)

# Find the distance to the enemy with distanceTo.
self.distanceTo(enemy)

# If the distance is less than 5 meters...
if a < 5:
if b:
self.cleave(enemy)

# ... if "cleave" is ready, cleave!
if b:

self.attack(enemy)
# ... else, just attack.
``````

i canâ€™t figure out what I am doing wrong! Iâ€™ll appreciate your help. Thanks!

Notice that youâ€™re setting â€śbâ€ť to be the result of whether cleave is ready. Then, later on, you see whether there is an enemy within 5 units. If there is, you check whether cleave is ready, if so - you cleave. Then, you check if cleave is ready, if so - you attack. You need to go check the second â€śif bâ€ť to be either â€śif not bâ€ť or â€śelse:â€ť

2 Likes

OHHHHHHH! thx a lot. i got it.

``````loop:
enemy = self.findNearestEnemy()

if enemy:
a = self.distanceTo(enemy)
if a < 5:
self.cleave(enemy)
else:
self.attack(enemy)
``````

2 errors:

1. You check if cleave is ready, but you donâ€™t do anything with the result.
2. Your `self.attack(enemy)` is too indented.
``````loop:
enemy = self.findNearestEnemy()

if enemy:
a = self.distanceTo(enemy)
if a < 5 and self.isReady("cleave"):    #Both must be true
self.cleave(enemy)
else:
self.attack(enemy)                  #Only 4 spaces relative to else
``````
1 Like

Thank you very much!