Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Clash of Clones yak trouble

hero.attack("Robin")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Erica")
hero.attack("Fidsdale")
hero.attack("Gimsley")
hero.attack("Jensen")
hero.attack("Stephanie")
hero.attack("Diane")
hero.moveXY(65, 64)
while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "ninja" or "soldier" or "archer":
        pass
    if enemy and enemy.type == "archer" or "ninja" or "soldier":
        hero.attack(enemy)

this is my code for clash of clones, the one problem i have is that even though i specified otherwise, I still shoot the yaks, any solutions?

What weapon are you using? Is your hero targeting the yaks, or is the arrow missing the target and hitting the yak?

A few other details, when you are checking the enemy.type you have to write out enemy.type for each type. Also, when you combine ‘and’ with ‘or’ checks, you need to put parenthesis around the or groups. If you don’t, it will skew the value.

if enemy and (enemy.type == "ninja" or enemy.type ==  "soldier" or enemy.type == "archer"):

I am using the sniper rifle, stacked reinforced emerald armor, speed ring, the precious, enchanted lenses and sharpsong. EDIT: I just got the twilight glasses

my hero is targeting the yaks

My first post will stop you from targeting the yaks by cleaning up the enemy.type line. You don’t need both a != and ==. One thing to think about here, your enemy has the same basic gear and more ogre friends will jump in later. Any type of special power will help a lot on this level.

there are not a lot of special powers for rangers.

and even with this

hero.attack("Robin")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Erica")
hero.attack("Fidsdale")
hero.attack("Gimsley")
hero.attack("Jensen")
hero.attack("Stephanie")
hero.attack("Diane")
hero.moveXY(65, 64)
while True:
    enemy = hero.findNearestEnemy()
    if enemy and (enemy.type == "archer" or "ninja" or "soldier"):
        hero.attack(enemy)
    else:
        pass

i still wind up fighting yaks

You need to have enemy.type before each enemy.type, not just a string of or with the type.

(enemy.type == "archer" or "ninja" or "soldier") # yours
(enemy.type == "ninja" or enemy.type ==  "soldier" or enemy.type == "archer") # mine

ok, thanks for the help.

What heroes do you have access to and what rings? Also, the Emperor’s glove is good on this level.

I am using amara on this level, have pretty much all the rings and no glove. and by the way, it appears that if the yak is closer then the clone, my hero will do nothing in this script

hero.attack("Robin")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Erica")
hero.attack("Fidsdale")
hero.attack("Gimsley")
hero.attack("Jensen")
hero.attack("Stephanie")
hero.attack("Diane")
hero.moveXY(74, 67)
while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == "archer" or (enemy.type == "ninja" or enemy.type == "soldier" or enemy.type == "ogre"):
        hero.attack(enemy)
    else:
        pass

oh and I have only 153 gems

That is correct. This is where using an array like hero.findEnemies really helps. Then a for loop or while index loop to go through each one to find the enemies you want to attack. You can keep the if statement as you have it, just need it in the loop.

Do you have any type of bombs instead of sharpsong?

only the weak charge.

I still think the weak charge is better than sharpsong in this situation. You can throw as many bombs as possible and stay out of range of many enemies. Try a few different rings and make sure you use their abilities to give you the upper hand.

ok, by the way, I got the com down to 107 with this code and the sniper

hero.attack("Robin")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Gemma")
hero.attack("Erica")
hero.attack("Fidsdale")
hero.attack("Gimsley")
hero.attack("Jensen")
hero.attack("Stephanie")
hero.attack("Diane")
hero.moveXY(74, 67)
while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == "archer" or (enemy.type == "ninja" or enemy.type == "soldier" or enemy.type == "ogre"):
        hero.attack(enemy)
    if enemy.type == "munchkin":
        hero.attack(enemy)
    else:
        hero.moveXY(66, 66)
        pass

I did it! ha! I used the auto rifle!

OH, please don’t post code that passed the level. We don’t want others just grabbing your code to pass a level. They won’t learn anything that way. They can pick up pieces of the puzzle from our conversation that should help, but we don’t want to show it all. You can either delete the post or just remove the code.
Thanks.

dont worry, i just figured out that that code is defective

i will delete it anyway though