Can I just see your code???
Or
@Lydia_Song or @milton.jinich try to run @Ryan_Wong 's code and see if it works for you
this way you can see the errors or something
my code:
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
def pickUpCoin():
# Collect coins.
item = hero.findNearestItem()
if item:
hero.move(item.pos)
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():
for soldier in hero.findFriends():
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():
for archer in hero.findFriends():
enemy = archer.findNearestEnemy()
if hero.distanceTo(enemy) <= 25:
if friend.type == "archer":
hero.command(friend, "attack", enemy)
else:
hero.command(archer, "move", {'x':24, 'y':47})
pass
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
I got it. Maybe because I have pender and I have boss start IV
lol I have boss star II
Maybe do command them to stay in the same place doing friend.pos
to spread them out
my main thing is that im getting null on line 33. If I can get that away then I should be good
So what is on line 33
You need to add an if enemy here:
between
and
And then indent as needed.
Lydia
my character started working but it still doesn’t work
is there a way that I can command the soldiers to go somewhere specific?
Yes, but in this level, you need to command your soldiers to attack their nearest enemy.
Your hero should only stay in the range of the reindeers
Lydia
Lydia what character do you use?
the problem is not your soldiers it is your archers
how???()20 chars as adds
Try instead of directly defining hero.findFriends() in your for-loop like here:
and here:
Define it separately first before the two, so like this:
friends = hero.findFriends()
for archer in friends:
and
friends = hero.findFriends()
for soldier in friends:
Lydia
I have to go can we do this later?
In your commandArcher() function.
After the for-loop,
you first check if the friend is the type archer
then define enemy as enemy = archer.findNearestEnemy()
then check if there is an enemy
then check if the distance to the enemy is less than 25
if it is then command archer to attack the enemy
if not then command the archer to move to x:24, y:47 like this: hero.command(archer, "move", {'x':24, 'y':47})
Lydia
Yes, of course!
Lydia