Help in clash of clones

if enemy.type != “sand-yak”:
do your attack code

1 Like

ok I’ll try that

post must be 20 character

1 Like

it says unterminated what does that mean?

post your code please

1 Like

I recommend you rewrite your entire code, and incorporate the tips we gave you. After your write it, post it here, so we can help you more.

1 Like
hero.moveXY(64, 70)
while True:
    enemies = hero.findEnemies()
    if enemy.type != “sand-yak”:
    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)

Again make that findNearestEnemy()

hero.moveXY(64, 70)
while True:
    enemies = hero.findNearestEnemy()
    if enemy.type != “sand-yak”:
    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)

make the else elif and put hero.canCast behind the elif and then cast it

you defined the wrong variable

hero.moveXY(64, 70)
while True:
    enemy = hero.findNearestEnemy()
    if enemy.type != “sand-yak”:
    if enemy.type=="soldier" or enemy.type=="knight" or enemy=="scout":
        if enemy:
            if hero.isReady("bash"):
                hero.bash(enemy)
            elif:
                hero.canCast("chain-lightning", enemy)
    else:
        if hero.health>hero.maxHealth/4:
            hero.shield()
        else:
            hero.moveXY(42, 77)

try to do what abc said

1 Like

alright i’lll try that

while True:
    enemy=hero.findNearestEnemy()
    if enemy:
        hero.canCast("chain lightning", enemy)
    else:
        hero.attack(enemy)
  1. Use an if statement checking if your hero can cast chain-lightning before casting chain-lightning
  2. How can you attack an enemy if there is no enemy?
  3. Use your bash ability.
1 Like

what do you mean on the 2nd one

What happens if there is no enemy you need to check if there is one

1 Like

I meant that you have an else statement following the if enemy and there is an attack statement.

1 Like

You can only bash when your hero is ready to bash, same with chain-lightning, so use if statements to check if your hero can perform and action. For bash, cleave, and other abiltites, that statement would be hero.isReady("ability"), but that is not the case for spells. Spells require the method hero.canCast("spell", target). Also, check which methods you can use and how to properly use them.

An example of using the cleave ability:

if hero.isReady("cleave"):
    hero.cleave(enemy)
else # this can also be an elif statement:
    #do what ever you need to
    hero.attack(enemy)

Here is a spell like poison-cloud:

if hero.canCast("poison-cloud", enemy):
    hero.cast("poison-cloud", enemy)
else # this can also be an elif statement:
    #do what ever you need to
    hero.attack(enemy)

Is this a bit more clearer @Ryan_Wong?

1 Like

@Ryan_Wong You wont be able to cast the chain lightning if your hero is not ready. Make an if loop
for example

if hero.canCast("chain-lightning")
hero.cast("chain-lightning")
1 Like

But don’t forget about indentation, when copypasting)
upd. and :

1 Like