Keeping Time; enemy is not defined, help!


#1

Okay, so I think the coding is good, but it keeps showing this message:

This is my code:

loop:
    # If it's the first 10 seconds, fight.
    enemy = self.findEnemies()
    if self.now() < 10:
        if enemy:
            if self.isReady("cleave"):
                self.cleave(enemy)
            else:
                self.attack(enemy)
        

    else:
        if self.now() < 30:
            items = self.findItems()
            x = item.pos.x
            y = item.pos.y
            self.moveXY(x, y)
        if self.now() > 30:
            if enemy:
                if self.isReady("cleave"):
                    self.cleave(enemy)
                else:
                    self.attack(enemy)
        
    # Else, if it's the first 30 seconds, collect coins.
    # After 30 seconds, join the raid!

Thanks!


#2

Self.findEnemies returns a list. You can’t attack a list (Well, you can, but not in a programming sense). You need to use self.findNearest first.


#3

Okay thanks, I couldn’t figure out what was wrong with it…
:relaxed:


#4

This game is fcking stupid


#6

It so isn’t! Codecombat is boss.