[SOLVED] Clash of Clones

from random import randint
epicCoder = randint(1, 2)
def dumb():
    hero.attack(hero)
def smart():
    hero.attack(enemy)

if epicCoder == 1:
    epicCoder = dumb()
    dumb()
elif epicCoder == 2:
    epicCoder = smart()
    smart()

Oh are for and in commands later on? (sorry if my questions sound dumb, i’m just curious)

Yeah you’ll learn them in cloudrip mountain.

Tho I am having trouble on for loops so please don’t ask me about them.

Ok. I’m still finding problems. My hero doesn’t respond to the code and the warnings say ‘Code never finished. It’s either really slow or in an infinite loop’. Please help.
Here is my code:

def FindArcher():
    enemies = hero.findEnemies()
    enemyindex = 0
    archer = None
    while enemyindex < len(enemies):
        enemy = enemies[enemyindex]
        if enemy.type == "archer":
            archer = enemy
            if archer.health < 0:
                hero.attack(archer)
            enemyindex += 1
        pass
    pass

while True:
    FindArcher()
    enemy = hero.findNearestEnemy()
    if enemy.type != "yak" and enemy.type != "Thoktar":
            hero.attack(enemy)
    else:
        hero.shield()

Think you want that < the other way round…

1 Like

ahhhh, thank you.

It still says it’s slow or in an infinite loop

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

while True:
    FindArcher()
    enemy = hero.findNearestEnemy()
    if enemy.type != "yak" and enemy.type != "Thoktar":
        hero.attack(enemy)
    else:
        hero.shield()

Also, delete the pass

Both of them?

That might not help a lot but it makes the code slower.

thank you.

Also try deleting the and enemy.type != "Thoktar" if that doesn’t work than I don’t know what to do.

ok, there is some problems with ur code.
Instead of:

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

use… maybe for loop

def FindArcher(enemies): # Here you use enemies to call the function
    for enemy in enemies: # so you don't have to put hero.findEnemies()
        if enemy.type is 'archer':
            while enemy.health > 0:
                hero.attack(enemy)
    pass


while True:
    FindArcher() # You just need this as you will only attack archers
    

WAY easier, right, you can use for loop without programmation 4

for i in range(4):# ==> This means repeat 4 time, uses "i" to loop. "j" works too
    hero.attack(hero)

hi @Joel_Greeley and welcome to the codecombat forum i hope you will find everything you will need here. and @EpicCoder999 what level do you get the steel striker? i dont have it.

You can buy that shield with gems. ( from the item store )

the swords i do have are: simple sword (+6) the sharpened sword (+10) the long sword (+27) and the kithsteel blade (+45) range (7).

the ones i can unlock are rune sword (+228) the sword of the temple (+53) and the sword of the forg… (+105) and i dont know the actual name of it so i did the 3 dots (and thats not all but those would be the most helpful ones for this.

It is a SHIELD!!

i know you can buy it but i dont have the level to buy it.