Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help with Kelvintaph-Defiler

I need help with the level Kelvintaph Defiler.
Here is my code:

def commandPaladin():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            hero.command(friend, "move", {'x': 22, 'y': 40})
            hero.command(friend, "move", {'x': 22, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 82})
            hero.command(friend, "move", {'x': 74, 'y': 82})
            hero.command(friend, "move", {'x': 75, 'y': 68})
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                hero.command(friend, "shield")
                if friend.canCast("heal") and friend.health < friend.maxHealth:
                    hero.command(friend, "cast", "heal", friend)


def commandHero():
    hero.moveXY(34, 15)
    hero.moveXY(34, 22)

def commandHelpers():
    friends = hero.findFriends()
    for friend in friends:
        paladin = friend.findByType("paladin")
        if friend.type == "archer":
            
            if paladin:
                hero.command(friend, "move", {'x': paladin.pos.x, 'y': paladin.pos.y})


def commandOthers():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldiers":
            enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                


commandHero()
while True:
    commandPaladin()
    commandHelpers()
    commandOthers()

can you please help me, I do not know what is wrong

I’m pretty sure that

gives you an array. Also,

should be

if friend.type == "soldier":
2 Likes

@minecraftLord77 great! thank you for that let me try.

@MidnightWolf39 could you try helping me with that because I did not exactly get that

@Speedypickle1, you should replace

with

if friend.type == "soldier":

also,

gives you an array like [paladin1.id, paladin2.id].

I’m pretty sure an array doesn’t have a position.

1 Like

I get that thank you @MidnightWolf39 I will try that

1 Like

here is my new code:

def commandPaladin():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            hero.command(friend, "move", {'x': 22, 'y': 40})
            hero.command(friend, "move", {'x': 22, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 82})
            hero.command(friend, "move", {'x': 74, 'y': 82})
            hero.command(friend, "move", {'x': 75, 'y': 68})
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                hero.command(friend, "shield")
                if friend.canCast("heal") and friend.health < friend.maxHealth:
                    hero.command(friend, "cast", "heal", friend)


def commandHero():
    hero.moveXY(34, 15)
    hero.moveXY(34, 22)

def commandHelpers():
    friends = hero.findFriends()
    for friend in friends:
        paladins = friend.findByType("paladin")
        paladin = paladins[0]
        if friend.type == "archer":
            
            if paladin:
                hero.command(friend, "move", {'x': paladin.pos.x, 'y': paladin.pos.y})


def commandOthers():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                


commandHero()
while True:
    commandPaladin()
    commandHelpers()
    commandOthers()

it gives me this error:

could you help me with that

1 Like

I see a problem your should be the one finding the paladin not your friends.

1 Like

@Ufy Thanks I understand that

it just gives me another error here is my new code:

def commandPaladin():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            hero.command(friend, "move", {'x': 22, 'y': 40})
            hero.command(friend, "move", {'x': 22, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 66})
            hero.command(friend, "move", {'x': 42, 'y': 82})
            hero.command(friend, "move", {'x': 74, 'y': 82})
            hero.command(friend, "move", {'x': 75, 'y': 68})
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                hero.command(friend, "shield")
                if friend.canCast("heal") and friend.health < friend.maxHealth:
                    hero.command(friend, "cast", "heal", friend)


def commandHero():
    hero.moveXY(34, 15)
    hero.moveXY(34, 22)

def commandHelpers():
    friends = hero.findFriends()
    
    for friend in friends:
        
        if friend.type == "archer":
            paladin = hero.findByType("paladin")
            if paladin:
                hero.command(friend, "move", {'x': paladin.pos.x, 'y': paladin.pos.y})


def commandOthers():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
                


commandHero()
while True:
    commandPaladin()
    commandHelpers()
    commandOthers()

and here is the error:

by the way @MidnightWolf39 and @Ufy I know this is off-topic but have you heard about the global tournament for codecombat? Here is the link:
https://codequest.codecombat.com/?utm_campaign=codequest&utm_medium=landingpage&utm_source=codecombat

2 Likes

Try to use moveXY instead of ‘move’

@Ufy Ok! But I am not sure that works

1 Like

Yeah I’m sorry you can’t command soldiers to moveXY, My brains been going through stress lately can’t think properly and can you repost your code?

1 Like

I suggest giving them a x and y to go to. you could send them to the chamber the paladin that the paladin is in. BTW how do they get free mine just sit afraid.