try using coin = hero.findNearestItem
Move this
before this
Andrei
so that made my hero get the coins but he dosent spawn a soldier
can i see your code?
also, do you have errors?
no errors
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
def pickUpCoin():
# Collect coins.
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
pass
def summonTroops():
# Summon soldiers if you have the gold.
if hero.gold < hero.costOf("soldier"):
hero.summon("soldier")
pass
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier(soldier):
# Soldiers should attack enemies.
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", target)
pass
# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandarcher(archer):
enemy = archer.findNearest(hero.findEnemies())
if enemy:
hero.command(archer, "attack", enemy)
else:
hero.command(archer, "move", archer.pos)
while True:
pickUpCoin()
summonTroops()
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
# This friend will be assigned to the variable soldier in commandSoldier
commandSoldier(friend)
elif friend.type == "archer":
# Be sure to command your archers.
commandarcher(friend)
pass
Donβt you think that you got wrong the sign?
Andrei
so now i have soldiers being summoned but they still kill the reindeer
i just noticed, you need to capitalize your functions when you call the like commandArcher(friend)
and not commandarcher(friend)
does that relly make a difference?
That is ok at it is @Mumbo_6.
Andrei
i cant use capital A or there is an error
sorry, i do not have my glasses on, it is corresct as it is, since you called the function commandarcher(friend)
yes it is (20character)
but the enemy gets to the reindeer to quick
Can you show us your recent code?
Andrei
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
def pickUpCoin():
# Collect coins.
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
pass
def summonTroops():
# Summon soldiers if you have the gold.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
pass
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier(soldier):
# Soldiers should attack enemies.
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
pass
# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandarcher(archer):
enemy = archer.findNearest(hero.findEnemies())
if enemy:
hero.command(archer, "attack", enemy)
else:
hero.command(archer, "move", archer.pos)
while True:
pickUpCoin()
summonTroops()
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
# This friend will be assigned to the variable soldier in commandSoldier
commandSoldier(friend)
elif friend.type == "archer":
# Be sure to command your archers.
commandarcher(friend)
pass
Here also check if the distance to the enemy is less than 25 meters. (PS and to get the bonus command the soldiers to retreat behind the archers when they are low on health)
Andrei
Andrei
so how would i do that? not the bonus (yet )
With archer.distanceTo(enemy).
Andrei