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