I tried reading other topics already, they didn’t help
I’m getting the “code is really slow or never finished” warning
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:
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()
The problem is in your commandSoldiers() function. You need an if enemy in there. Also, you don’t need to define soldier, but you need to only command soldiers (you can’t command the peasant), so you need to include a statement to the effect of, if friend.type == "soldier". I was able to get your code to work by just changing the last three lines of the commandSoldiers() function.
can you help me, I tried doing as you said but the flower dosent grow to its full size
# 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 friend.type == "soldier":
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()
Him Ive been trying to figure this out. can you help me
…
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 = hero.findNearestEnemy()
soldiers= hero.findByType(“soldier”)
for soldier in soldiers:
if friend.type == “soldier”:
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()
pickUpNearestCoin()
# commandSoldiers()
# pickUpNearestCoin()
# 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 = hero.findNearestEnemy()
soldiers= hero.findByType("soldier")
for soldier in soldiers:
if friend.type == "soldier":
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()
pickUpNearestCoin()
# commandSoldiers()
# pickUpNearestCoin()
Thank you! But for some reason It still telling me that Is wrong. Is there anything else that you know is wrong with the rest of the code. That you would know