The Agrippa Defense Python. Please Help


#1

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)
        self.isReady("cleave")
        b = self.isReady("cleave")
    
        # 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! :smile:


#2

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:”


#3

OHHHHHHH! thx a lot. i got it. :smile:


#4
loop:
    enemy = self.findNearestEnemy()
    
    if enemy:
        a = self.distanceTo(enemy)
        if a < 5: 
            self.isReady("cleave")
            self.cleave(enemy)
        else:
                self.attack(enemy)

#5

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

#6

Thank you very much!