#1

I need Help on Kelvintaph Crusader.
Here is my code:

``````loop:
archer = self.findByType("Archer")
enemy = self.findNearest(self.findEnemies())
friends = self.findFriends()
freind = self.findNearest(friends)
witch=self.findByType("Witch")

for friend in friends:
friende=friend.findNearest(friend.findEnemies())

if witch:
self.command(friend, "attack", "Yzzrith")
else:
self.command(friend, "attack", friende)

self.moveXY(42, 16)
self.moveXY(25, 18)
self.wait(1)
self.attack("Muul")
self.attack("Muul")
self.moveXY(69, 16)
self.moveXY(53, 14)
self.wait(5)
self.moveXY(69, 15)
self.wait(3)
self.moveXY(41, 15)
``````

My hero does fine, takes down catapults and brawlers, but my soldiers attack the witch then don’t attack, but I used an if else to check if there is a witch.
Help?

#2

Instead, i think you should do

``````for friend in friends:
friendWitch = friend.findNearest(friend.findByType('witch', friend.findEnemies))
if friendWitch:
self.command(friend, 'attack', friendWitch)
else:
self.command(friend, 'attack', friend.findNearest(friend.findEnemies())

``````

I hope this might help.
tell me if it doesn’t. Bye!

#3

I copied and pasted that code and this is what I got:

What is happening?

#4

You really shouldn’t be using `moveXY()`, because otherwise you can’t command your minions.

You’ll have to rewrite your code such that you’ll use `move()` and conditionals to control your hero, something like:

``````# get friends and enemies
loop:
for friend in friends:
# command friends

# then control hero with conditionals
if not movedCenter
# self.move() to center
if determineIfInCenterSomehow(): movedCenter = True
elif not movedEnd
# self.move() to end
if determineIfInEndSomehow(): movedEnd = True
# etc...
``````

#5

You’ll also want to make sure you do `findByType("witch")` instead of `findByType("Witch")`–it’s case-sensitive.

#6

Thanks! i’m in the process of updating my code.

By the way, when codecombat doesn’t take self as valid, is it a bug?

#7

@nopressure1q2w I believe it depends on where and how you are using it. Please post the code you are having issues with so we can properly test and look for bugs.

#9

Bug is gone but I haven’t solved the level

#10

I’m stuck again.

``````loop:
archer = self.findByType("Archer")
enemy = self.findNearest(self.findEnemies())
friends = self.findFriends()
freind = self.findNearest(friends)
witch=self.findByType("witch")

for friend in friends:
friende=friend.findNearest(friend.findEnemies())

if witch:
self.command(friend, "attack", "Yzzrith")
else:
self.command(friend, "attack", friende)

if self.pos.x<41:
self.move({'x':41,'y':15})
if self.pos.x=41:
center=True
elif self.pos.x<78:
self.move({'x':78,'y':14})

#self.move({'x':25,'y':18})
#self.wait(1)
#self.attack("Muul")
#self.move({'x':62,'y':16})
#self.move({'x':53,'y':14})
#self.wait(5)
#self.move({'x':69,'y':15})
#self.wait(3)
#self.move({'x':41,'y':15})
``````

I survive but my troops still kill the witch then stand still and get slaughtered.
Help!