Kithgard Brawl - can't find my bug


#1

I receive an "Unexpected token { " error, but can’t see what I messed up. I wanted to cleave when the cool down is over and enemies are close, else attack normally. The error points to the “else” line.

var enemy = this.findNearestEnemy();
if (this.isReady("cleave") && this.distanceTo(enemy) < 10) {
    this.cleave(enemy);
    }
else (enemy) {
        this.attack(enemy);
    }

#2
else {
        this.attack(enemy);
    }

#3

Thanks. I don’t know why I wanted to put an argument there.

Now I get for the “if” line: “distanceToTarget is null. Does the target exist? (Use if?)”

I am using if. :unamused:

I’m pretty sure I copied this from the panel correctly…


#4

I think I know why you put the (enemy) there (though at the wrong place.
It might be that there is no enemy when checking the distance, so you want to if (enemy) {...}.


#5

I keep getting arugmenterror in this code, can someone help pls?
enemy = self.findEnemies()
loop:
if enemy: self.isReady(“cleave”)
self.cleave(enemy)
if self.isReady(“electrocute”):
self.electrocute(enemy)
else:
self.attack(enemy)
self.attack(enemy)


#6

Your code suggest that you’re trying to first make sure that there actually is an enemy and then do something about it, so the line:

should be split into two separate if-statements.


#7

k noted thx for your help!!!