My herrow always be attacted by the cow not the other enemies.
I have tried many times but failed .hope some one give me some ideas.thanks.
Try to exclude the “cow” (by the way, it’s a yak):
if enemy.type != "sand-yak":
# do this and that
Cheers
yes, you are right. I have done, failed the same.here are my code
loop {
var friend=this.findNearest(this.findFriends());
var enemies=this.findEnemies();
var enemy=this.findNearest(enemies);
if (enemy.type != "Sand-yak") {
if (this.isReady("bash")) {
this.bash(enemy);
}
else if (this.isReady("cleave")) {
this.cleave(enemy);
}
else {
this.attack(enemy);
}
}
else {
this.move(friend.pos);
}
}
Try to replace the capital ‘S’ with a small ‘s’ in sand-yak
…
thanks, I have successfully to pass it .however it said that : Line 38 Cannot read property ‘type’ of null.
What does it mean?
Although I cannot see what’s on your line 38, I guess this happens because there are no more enemies, and so var enemy=this.findNearest(enemies)
is null
, thus the expression if (enemy.type != "sand-yak")
tries to read the ‘type’ property of a non-existent enemy, null
.
Make sure you check if there is an enemy: add an if enemy
statement before that, and you should be fine.
Thank you for your good ideas.
u can use a one liner doing both the if statements:
if enemy and enemy.type != "sand-yak":
Note that the sequence of two if arguments is important. The if statement is checking for enemy, and then type not equal to sand-yak… other way around:
if enemy.type != "sand-yak" and enemy:
will cause problem if there is no enemy (by checking enemy type first when there is no enemy)
Cheers