``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: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=9)
GregW
23
I’m sorry, I don’t know how.
(To format code)
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()?
GregW
29
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
GregW
35
It does! Thank you so much! I finally learned how to do this!
GregW
36
Thank you all for your time and effort!
Great! That’s great! Good luck!