Kelvintaph Crusader Stuck

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)
    paladin=self.findByType("paladin")
    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?

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!

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

What is happening?

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...

Your original code for commanding your minions should work fine, though.

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

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?

@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.

Bug is gone but I haven’t solved the level

I’m stuck again.

loop:
    archer = self.findByType("Archer")
    enemy = self.findNearest(self.findEnemies())
    friends = self.findFriends()
    freind = self.findNearest(friends)
    paladin=self.findByType("paladin")
    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!

um can someone please tell me how to get loop cause I don’t have that function

you dont get for-loops until you reach Cloudrip Mountain @tacotacokitty
secondly @nopressure1q2w i found your error

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

dont attack things by name the name is randomized
secondly,

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

first you have a typo second why would you attack one of your own troops attack the enemy instead
and when you first define friend…

freind = self.findNearest(friends)

you have another typo

Hope this helps!