I can’t figure it out its so frustrating!!!
here is my code:
# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
soldiers = hero.findByType("soldier")
for soldier in soldiers:
if enemy:
hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
peasant = hero.findByType("peasant")[0]
while True:
summonSoldiers()
# commandSoldiers()
commandSoldiers()
# pickUpNearestCoin()
pickUpNearestCoin()
please help
Try to do this
friends = hero.findByType("peasant", hero.findFriends())
for friends in friends:
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack" enemy)
This way it attacks the closest enemy to the peasant
so where should I put the code?
do it in the command friends thing
huh I don’t know where is the command friends thing
Do it for command soldiers.
here is my entire code:
# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
soldiers = hero.findByType("soldier")
for soldier in soldiers:
if enemy:
hero.command(soldier, "attack", enemy)
friends = hero.findByType("peasant", hero.findFriends())
for friends in friends:
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
peasant = hero.findByType("peasant")[0]
while True:
summonSoldiers()
# commandSoldiers()
commandSoldiers()
# pickUpNearestCoin()
pickUpNearestCoin()
show me your new code now and what happens
here is my new code:
# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findByType("peasant", hero.findFriends())
for friends in friends:
enemy = hero.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
# Define the function: pickUpNearestCoin
friends = hero.findByType("peasant", hero.findFriends())
for friends in friends:
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
peasant = hero.findByType("peasant")[0]
while True:
summonSoldiers()
# commandSoldiers()
commandSoldiers()
# pickUpNearestCoin()
pickUpNearestCoin()
and it say’s try hero.findFriends
1 Like
Ill help you soon, just let me start up CoCo ok?
6 Likes
Thanks for welcoming me! I’ve been here before tho 
4 Likes
um how do I do that step?
1 Like
delete the command Soldiers funtion and instead put this:
def commandSoldiers():
for soldier in hero.findFriends():
enemy = soldier.findNearestEnemy()
if enemy and soldier.type == "soldier":
hero.command(soldier, "attack", enemy)
3 Likes