def pickUpCoin():
hero.toggleFlowers(False)
while True:
coin = hero.findNearestItem()
hero.move(coin.pos)
pass
def summonTroops():
if hero.costOf(“soldier”):
hero.summon(“soldier”)
pass
def commandSoldier(soldier):
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy :
hero.command(friend, “attack”, enemy)
pass
def commandArchers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy and friend.distanceTo(enemy) < 25:
hero.command(friend, “attack”, enemy)
else:
hero.command(friend, “move”, {“x”:friend.pos.x, “y”:friend.pos.y})
while True:
pickUpCoin()
summonTroops()
friends = hero.findFriends()
for friend in friends:
if friend.type == “soldier”:
commandSoldier(friend)
elif friend.type == “archer”:
commandArchers()
pass
my archers just attack the nearest enemy they find (the one on the other side of the map)
Could you format your code as it is explaned here:
https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521/2
So we can help you solve the level?
def pickUpCoin():
hero.toggleFlowers(False)
while True:
coin = hero.findNearestItem()
hero.move(coin.pos)
pass
def summonTroops():
if hero.costOf("soldier"):
hero.summon("soldier")
pass
def commandSoldier(soldier):
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy :
hero.command(friend, "attack", enemy)
pass
def commandArchers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy and friend.distanceTo(enemy) < 25:
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {"x":friend.pos.x, "y":friend.pos.y})
while True:
pickUpCoin()
summonTroops()
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
commandSoldier(friend)
elif friend.type == "archer":
commandArchers()
pass
def pickUpCoin():
hero.toggleFlowers(False)
while True:
coin = hero.findNearestItem()
hero.move(coin.pos)
pass
def summonTroops():
if hero.costOf(“soldier”):
hero.summon(“soldier”)
pass
def commandSoldier(soldier):
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy :
hero.command(friend, “attack”, enemy)
pass
def commandArchers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy and friend.distanceTo(enemy) < 25:
hero.command(friend, “attack”, enemy)
else:
hero.command(friend, “move”, {“x”:friend.pos.x, “y”:friend.pos.y})
sorry, ill, do it again with the formation : )
Remove this loop
Here put
commandArchers(friend)
Here put
commandArchers(friend)
Delete this loop
Instead of soldier put friend
Also, remove this loop
def pickUpCoin():
hero.toggleFlowers(False)
while True:
coin = hero.findNearestItem()
hero.move(coin.pos)
pass
def summonTroops():
if hero.costOf(“soldier”):
hero.summon(“soldier”)
pass
def commandSoldier(soldier):
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy :
hero.command(friend, “attack”, enemy)
pass
def commandArchers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy and friend.distanceTo(enemy) < 25:
hero.command(friend, “attack”, enemy)
else:
hero.command(friend, “move”, {“x”:friend.pos.x, “y”:friend.pos.y})Preformatted text
for some reason it does’t want to format
Can you correct the things I told you that are wrong?
So have you finished the level?
ill try what you said and run it
it still doesn’t work. I’ll send you the new code.
def pickUpCoin():
hero.toggleFlowers(False)
while True:
coin = hero.findNearestItem()
hero.move(coin.pos)
pass
def summonTroops():
if hero.costOf("soldier"):
hero.summon("soldier")
pass
def commandSoldier(friend):
friends = hero.findFriends()
enemy = friend.findNearestEnemy()
if enemy :
hero.command(friend, "attack", enemy)
pass
def commandArchers(friend):
friends = hero.findFriends()
enemy = friend.findNearestEnemy()
if enemy and friend.distanceTo(enemy) < 25:
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {"x":friend.pos.x, "y":frien.pos.y})
while True:
pickUpCoin()
summonTroops()
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
commandSoldier(friend)
elif friend.type == "archer":
commandArchers()
pass
Remove this loop. This is what is wrong
won’t removing the while loop make it run only once?
Yes, remove it. Please! Now is it alright?