sorry that seems like a riddle what
Define enemy as a person, not a distance. Put the distance line inside the if enemy
line
[en_US.composer.my_button_text]
so now ive got this as my code so far
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
def pickUpCoin():
# Collect coins.
if coin:
coin = hero.findItems()
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):
friendType = hero.findByType("friendType", hero.findFriends())
if enemy == hero.findNearestEnemy() > 25:
hero.command(archer, "target", 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(friends)
pass
but now this line
if enemy == hero.findNearestEnemy() > 25:
has an error saying there is no enemy
@Anna
first define the variable enemy before you do anything with an if. then say something like
if hero.distanceTo(enemy) < 25:
for the distance line
how do i do that again? define a variable
to define an enemy type enemy = hero.findNearestEnemy()
i already have that (20)
In the function commandArcher(archer)
?
It has to be separate from your if’s because that will confuse the hero/archer.
Instead of this, put that enemy is archer’s nearest enemy.
And you now do not need this part of the code, do you?
Andrei
so let me get this right you want me to put this
enemy = archer.findNearestEnemy()
instead of this?
friendType = hero.findByType("friendType", hero.findFriends())
and im pretty sure i need
== hero.findNearestEnemy()
i can try without it
Yes, that is what I mean.
Andrei
Try without it and see if it workes.
Andrei
well in that case there is an error saying archer has no method
Can I see your code?
Andrei
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
def pickUpCoin():
# Collect coins.
if coin:
coin = hero.findItems()
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.findNearestEnemy()
if enemy:
hero.command(archer, "target", 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(friends)
pass
Why do you use the target command that does not exists when you want to command to attack?
Andrei
where is that in the code?
Right here is where you should make the change.
Andrei