Help on Backwoods Brawl


#1

So heres my code, the console tells me the target is null, but I clearly defined “enemy”, and thats the target (Code Below). Any suggestions?

loop {
var enemy = (this.findNearest(this.findEnemies()));
if (this.distanceTo(enemy) < 10) {
    if (this.isReady("cleave")) {
        this.cleave(enemy);
        this.shield();
        
    }
    else {
        this.attack(enemy);
        this.shield();
    }
}
}

#2

but what is the target defined as if there is no enemy? … null

so you have to check:

if (enemy) 

before you use it.

(and for reference on other levels: sometimes the human eye can always see an enemy, but that doesn’t mean there wasn’t a split second when there was no enemy…)


#3

Caleb7, Vievo’s statement is important for a lot of reasons… but below is an additional, very important one.

Also, it doesn’t mean that your hero can see the enemy too…


#4

try this:

loop:
    enemy = self.findNearest(self.findEnemies())
    if enemy :    
        if self.isReady("cleave") :
            self.cleave(enemy)
        else :
            if self.isReady("bash") :
                self.bash(enemy)
            else :
                self.attack(enemy)

#5

Thank you all, this solves my problem.