Targeting enemy types

I’m doing Backwoods treasure in the forest. I’m having trouble targeting one enemy type. Here’s may code. (First time posting so sorry if my formatting is off.)

while True:
    item = hero.findNearestItem()
    enemy1 = hero.findNearestEnemy()
    enemies = hero.findEnemies()
    enemyCount = 0
    for enemy in enemies:
        distance = hero.distanceTo(enemy)
        if  distance < 10:
            enemyCount = enemyCount + 1
    if enemy1:
        if enemy1.type == "ogre" | enemy1.type == "scout":
            hero.attack(enemy1)
            hero.attack(enemy1)
            hero.attack(enemy1)
        else:
            hero.attack(enemy1)
    if enemyCount > 5:
        hero.cleave(enemy1)
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    else:
        hero.moveXY(40, 33)

First, what level are you on. Second. Can you explain what your code is supposed to do and how

works. I am a little confused on how this code works. Also a screenshot would be helpful.

-@Luke10

Is the problem. Try and.

I’m on Backwoods treasure. I set “enemy1” to the nearest enemy. Then I set all enemies I can see as “enemies”. The I set a float variable called “enemyCount” and I set it to zero. the I create another variable called “distance” which is set to the distance from me to the enemy. In a for loop I make it to where if distance is less than five then increase “enemyCount” by 1. Then I have been trying to use a nested if statement to attack scouts and ogres before going back to pick up items. I’ll get back to you with the screenshot.

1 Like

Sorry, but that doesn’t quite work. But with re-reading it I didn’t fully explain the problem. I want to target those enemy types and attack them multiple times while I attack anything else once. I still attack those enemies but I only attack once as if they were normal enemies.

(twenty Characters )

com-video-to-gif
There’s a gif of the level.

1 Like

You need to start over. I think there that @ducky was right about

but if that doesn’t work you need to start over

Like re-write the entire code?

Well you already know from what you explained to me about what your code does, the basics of what needs to happen. Also if you reset it, You will still have the comments. I honestly think you should. If you need any more help, you can post again on this topic or message me personally and I’ll be happy to help!

-@Luke10

1 Like

Hi can you pm me and also send me your items?
Happy to help.
@Eugene_Ang

In codecombat, it is not possible for someone to transfer inventory to some else. You can either earn gems to buy certain items by completing levels, or buy either subscription that codecombat offers and you will receive and new character, gems, and XP every month.

-@Luke10
:fox_face::fox_face::fox_face:

I think @Eugene_Ang meant: “can you send a screenshot / list of the items”, not the physical game items.
:lion: :lion: :lion:

Ohhh. ok! Sorry @Eugene_Ang if that’s what you meant. Thanks @Deadpool198

(Please dont edit my posts for no reason moderators (Chaboi_300 specifically)

1 Like