Commanding Soldiers

``def commandSoldier()
if hero.gold > 20:
hero.summon(“soldier`def commandSoldier():
friends = hero.findFriends()
for friend in friends:
enemies = hero.findEnemies()
enemy = friend.findNearest(enemies)
if enemy:
hero.command(friend, “attack”, enemy)

def summon():
if hero.gold > 20:
hero.summon(“soldier”)``

Get items and run the functions by yourself. :slight_smile:

I’m sorry, I don’t know how. :flushed: (To format code)

how 2 wot? (20chars)

Ok.
while True:
commandSoldier()
summon()

I think summon should use a parameter for what type to summon… be much easier that way

There are two typos in here BTW.

Why not just do enemy=hero.findNearestEnemy()?

I don’t know how to format my code. The posting stuff is confusing to me. Again, sorry for all the trouble.

no prob. just do a
“```”
codegoeshere

“```”

of course without the quotes

just need the ``` 20 chars

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            enemies = hero.findEnemies()
            enemy = friend.findNearest(enemies)
            if enemy:
                hero.command(friend, "attack", enemy)

def summon():
if hero.gold > 20:
    hero.summon(“soldier”)

while True:
    summon()
    command()
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)


    
1 Like

Just put def commandSoldier(): on top

Tell me if it works.

It does! Thank you so much! I finally learned how to do this!

Thank you all for your time and effort!

No probs! Happy 2 halp!

Great! That’s great! Good luck!