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
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
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.
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.
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.