Help in clash of clones

so my new code should be:

hero.moveXY(64, 70)
while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    if enemy.type=="soldier" or enemy.type=="knight" or enemy=="scout":
        if enemy:
            if hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.cast if ready("chain-lightning", enemy)
    else:
        if hero.health>hero.maxHealth/4:
            hero.shield()
        else:
            hero.moveXY(42, 77)

Not quite, the method for checking is a spell is ready to be used is hero.canCast("spell", target), in this case spell should be chain-lightning, and target should be enemy.

1 Like

you need to rewrite this part and again findNearest makes a ARRAY you want to attack a unit

I dont know python but shouldnt the code be like else if(hero.canCast(“spell”))

hero.moveXY(64, 70)
while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    if enemy.type=="soldier" or enemy.type=="knight" or enemy=="scout":
        if enemy:
            if hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.canCast("chain-lightning", enemy)
    else:
        if hero.health>hero.maxHealth/4:
            hero.shield()
        else:
            hero.moveXY(42, 77)

no you need an else if hero.canCast(“spell”)

Yes like that, except you should keep the canCast statement with the else, making it an elif.

1 Like

you need to cast chain lightning and again you want to attack a UNIT

2 Likes
if hero.canCast("spell", target):
    hero.cast("spell", target)

This would be the correct format for any spell in python.

2 Likes

And since you havent leared for loops yet just do findNearestEnemy

2 Likes

Javascript would be

if(hero.canCast("chain-lightning")){
hero.cast("spell", target)
}
1 Like

Can you type the whole code down since I don’t really get what you guys are saying

Oh and make sure to only attack enemies that are not sand yaks

1 Like

Like I said before you might want to attack enemies that are not type sand-yaks.

1 Like

We cant post solutions on the forum

3 Likes

but I never wrote to attack sand yaks

You wouldnt learn anything if we just posted the answer

1 Like

well if you do findNearestEnemy the sand yaks are a enemy and your hero will attack them

so then what should I write for that since I need to have findNearestEnemy in order to attack

@Ryan_Wong, posting solutions is prohibited, however, we can give you help. Use hero.findNearestEnemy() first and define the variable as enemy. Next you should find if there is an enemy. If you can bash, the bash. Otherwise of you can cast chain-lightning, cast chain-lightning. If you can’t do both of these, then attack the enemy. Only bash, cast chain-lightning, and attack if the enemy’s type is not a sand-yak type. Your allies will help greatly, and try to kill your clone first.

EDIT: I accidentally replied to the wrong post.

3 Likes