Cannot attack scout (clash of clones - Python)

hi there,

im in the process of putting some ideas together to tackle clash of clones.

i’m having a problem attacking scouts with the following code though. The hero stands there and does nothing but i get no error. this is true even if i stand my hero next to a scout as well.

here is the code:

enemies = hero.findEnemies()
enemyIndex = 0

while True:
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.type == "scout":
            while enemy.health > 0:
                hero.attack(enemy)
    
        enemyIndex += 1

oddly though, the same code does work for archers.

enemies = hero.findEnemies()
enemyIndex = 0

while True:
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.type == "archer":
            while enemy.health > 0:
                hero.attack(enemy)
    
        enemyIndex += 1

any ideas?
thanks :slight_smile:

What’s your equipment? :smiley:

Rachel

Hey Rachel, here is my Eqp.

2 Likes

I can’t find any errors(not sure if that’s a good thing or bad thing :sweat_smile:), sorry :frowning:

Maybe @abc, @PeterPalov, and/or @Falcons118 could help, sorry again :frowning:

Rachel

1 Like

Try removing thornprick and working it out.

Reply to your first post ( I see only your posts the topic ):

# if you run this code
scout = hero.findByType("scout")[0]
if scout:
    hero.say(scout.id)
else:
    hero.say("Not a single  scout")
# you'll see there are no scouts, that's the reason your first code snip doesn't work

# so comment the above code ( hero.say takes valuable time)
# then kill the archers , no need to be in a while True loop, this is your original code

enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if enemy.type == "archer":
        while enemy.health > 0:
            hero.attack(enemy)
    enemyIndex += 1

# you have some more work to do in the main while True loop
while True:
    # find the nearest enemy
    # if enemy
        # attack the enemy
1 Like

Hey there, i see your gears good, and thats bad. Try getting shields with the bash ability, and get the emperor’s gloves to use the lightning function. The reason you want trash but decent armor is to one-shot your clone with chain lightning but still survive the basic ogres. You want to equip slow boots to make sure you don’t outrun your troops and die. Remove thornprick, it has no use as after the battle against clones, the ogres can one-shot you. As for why your code isn’t going as planned, “scout” refers to green munchkins, which do not appear in the level, “archer” refers to the archers. try using, “soldier” instead.

1 Like

if you want me to go slower, i can explain it step by step

1 Like

Thanks for the replies guys im not by my pc atm so i cant look at what you guys advising properly. I’ll take a look later when im back.

Ty all

1 Like

Hi all,

ive decided to completely change my tact with this level.
ty all for your replies but im going to work on my new code for a while.
if i have any questions i’ll put it in a new thread as my new code is completely different.

many thanks.

I think it will be hard without changing a little bit the armour and the weapon. Solution with a min health and code close to your idea:


please , don’t create new clash of clones tread - it’s the most regular and banal help topic :slight_smile:

the issue i’m having is targeting certain enemy types.
at the minute im trying to create a function that will attack archers only to no avail.
the idea is that if it works i can create a function for each enemy type.

here is the code if you don’t mind taking a look. hero moves straight to the else statement.

attackArcher = hero.findByType("archer")
enemy1 = attackArcher
enemy1Index = 0

## Attacks Archers
def attack1():
    attackArcher = hero.findByType("archer")
    while enemy1Index < len(attackArcher):
        enemy1 = attackArcher[enemy1]
        enemy = enemy1
        if enemy:
            hero.attack(enemy)
        else:
            hero.say("attack1 problem")
    enemy1Index += 1
    
attack1()

Thank you so much.
I passed the level.

You really simplified it for me. i was going crazy and thanks to you its done!! :grin: :grin: :grin:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.