I am really confused, please help me!
while True:
item = hero.findNearestItem()
if item:
hero.move(item.pos)
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
# Careful! If your soldiers are defeated, a warlock will appear!
# Если нет, прикажи следовать в правую часть карты.
if (enemy):
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {'x': 69, 'y': 37})
what’s not working? it’s also a subscriber level so i can’t help too much, but i can try.
This is the problem, one of my soldiers always dies.
while True:
item = hero.findNearestItem()
if item:
hero.move(item.pos)
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
# Careful! If your soldiers are defeated, a warlock will appear!
if enemy:
if friend.health > 20:
hero.command(friend, "attack", enemy)
elif friend.health < 20:
hero.command(friend, "move", {'x': 29, 'y': 42})
else:
if friend.health > 20:
hero.command(friend, "move", {'x': 69, 'y': 37})
elif friend.health < 20:
hero.command(friend, "move", {'x': 29, 'y': 42})
My new code. I will check if it works.
Ha! It works! After I change all of the 20s to 50s it worked!