Double, double toil and trouble my soldiers keep getting burned and cauldron bubble.
Here is my code:
def chooseSoldierTarget():
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex<len(enemies):
enemy = enemies[enemyIndex]
if enemy.type == 'witch':
while enemy.health > 0:
hero.command(friend, "attack", enemy)
enemyIndex+=1
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
if friend.type == "soldier":
chooseSoldierTarget()
pass
1 Like
you have to command your archers to attack the nearest enemy
Yea, but the soldier code des not work.
you should command the soldiers inside the chooseTarget function
and for the witch you could try
witch = friend.findNearest(friend.findByType("witch"))
Instead of putting this in the while loop
command the soldiers in the function
P.S you should also command the archers in that function
make the archers attack the nearest enemy
The soldier code is still giving me code never finished
but did you change your code?
post your new code please
Sorry if this takes a second my computers fan is having a seizure
1 Like
friend has not method find by type
My bad it should have been hero…
but when I run it with friend.findByType
I get success …
Okay, I can’t play and check now though.
well I had friend.findbytype and it works for me…
1 Like
# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
def chooseSoldierTarget():
if friend.type == "soldier":
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex<len(enemies):
enemy = enemies[enemyIndex]
witch = hero.findNearest(hero.findByType("witch"))
if enemy.type == witch:
while enemy.health > 0:
hero.command(friend, "attack", enemy)
enemyIndex+=1
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
chooseSoldierTarget()
pass
shouldnt you be using a for loop to command the soldiers???
you should use a for loop in the function to command your soldiers
It tells me that that is illegal