Caleb7
March 30, 2015, 1:34am
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();
}
}
}
Vlevo
March 30, 2015, 2:28am
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…)
1 Like
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…
bugot1
March 30, 2015, 7:43pm
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)
Caleb7
March 30, 2015, 9:58pm
5
Thank you all, this solves my problem.