[Solved] I tell him "don't attack the yak!", he attacks the yak

I’m trying to make sure that after finishing off the ogres, hero won’t go against the yaks:

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "yak":
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)
    elif enemy and enemy.type == "yak":
        hero.moveXY(enemy.pos.x - 20, enemy.pos.y + 20)
    pass

but, of course he goes attacking the yak in Clash of Clones!
Why is he doing that?

if hero.canCast(“chain-lightning”):
# and
if hero.isReady(“chain-lightning”):
# are equivalent

hero.canCast("chain-lightning", enemy):

defines if hero can physically attain the enemy ( you can see the enemy with see-through-wall glasses, but you cannot harm him)

This was the answer to your question in How to cast "chain-lightning"
You are attacking the yaks because the bounceRange is 20m and bounceCount is 8.

  1. Thanks!
  2. Where did you find this stats sheet for Chain lightning?
  3. Why not post the answer to my chain-lightning question in that other thread?
  4. I don’t understand your answer to the yak-question: I specified with enemy.type that if it’s a yak, it shouldn’t be attacked, but hero runs toward it to attack with the sword. That doesn’t have anything to do with chain-lightning, does it?

1.My pleasure
2. https://codecombat.com/editor/thang : Search Thang Types Types Here : Emperor’s Gloves :
https://codecombat.com/editor/thang/emperors-gloves : Components
3. My mistake - too many open tabs
4. If you’ re using chain lightning it will bonce toward nearby enemies and I think friends included - it’s a force of nature :slight_smile: I’ve seen the lightning crossing huge distances from enemy to enemy. From your code excerpt I think the lightning annoyed the yaks.

1 Like

But it was never cast (see the other thread about Chain Lighting), it doesn’t work for me :frowning:

Why dont you not cast chain lightning. Because if you do you cant control where it will go.

To answer your question, the enemy.type is “sand-yak” NOT “yak”

1 Like

Thanks, that was it!
Yay, desert completed!

1 Like