List of Enemy Types?

I’m having trouble targeting enemies by type in the level i’m working on, because i don’t know the names of the enemy types, and the specific type i’m trying to kill I can’t target to learn its type with self:say(enemy.type).

Specifically i’m working on clash of clones and would like to target the archers.
i’ve tried “archer”, “ranger”, and “thrower”, and none of them work.

However, is there a handy reference where one can look up what each type of enemy is? If not, can someone provide a list of enemies and their types?

3 Likes

You could click on an enemy to see it’s type (basically you click on a unit, then at the bottom it shows that unit’s portrait, name, and type like this):

Just make sure to lowercase the name when you check with unit.type or findByType(type).

4 Likes

I figured it would be something simple like this. thank you

On the level Clash of Clones the enemy has the same type of units as you, so you would first need to find your enemies, and then identify the different types:

enemyArchers = self.findByType("archer", self.findEnemies())

If you don’t have the findByType() method, you can do it this way:

enemies = self.findEnemies()
enemyArchers = []
for enemy in enemies:
    if enemy.type == "archer":
        # append it to the list
        enemyArchers.append(enemy)

Or with list comprehension (warning! advanced trickery! :smile:)

enemyArchers = [enemy for enemy in self.findEnemies() if enemy.type == "archer"]
3 Likes

this is helpful, thank you, but what if you do not know the enemy unit type? Like for example a yak, which type would that be?

it would be a yak. that’s the enemy type. The name is the enemy type itself.

If you don’t know the enemy type, just click on it, as explained about 3 comments above


it would be a yak. that’s the enemy type. The name is the enemy type itself.
[/quote]
Wrong. The enemy type for yaks is “sand-yak”.

1 Like

Yeah that’s what I meant, thanks for clearing that up! :+1:

hi, for enemy.type it says there is an eror. could someone help please here. i have put dashes on the incorrect sentece

while True:
    enemy = hero.findNearestEnemy()
    # With AND, the type is only checked if enemy exists.
    ///if enemy.type == "munchkin":///
        hero.attack(enemy)
    # Find the nearest item.
    item = hero.findNearestItem()
    # Collect item if it exists and its type is "coin".
    if item.type == "coin":
        hero.moveXY(item.pos.x, item.pos.y)

You haven’t checked if the enemy exists.