# paladin.canCast('heal',paladin) "Paladin has no method canCast"

**URL:** <https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342>\
**Category:** Level Help\
**Created:** [September 4, 2021, 11:22pm UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342 "2021-09-04T23:22:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![charliefik](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@charliefik](https://discourse.codecombat.com/u/charliefik)\
**Post date:** [September 4, 2021, 11:22pm UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/1 "2021-09-04T23:22:33Z")

</div>

Hi,

I am trying to do level kelvintaph burgler but I keep getting an error message saying that paladin.canCast is not a function.

I am not sure why this isn’t working as I’ve used this before so it should do.

Any ideas?

Man thanks,

The code I’m using is below the screen shot

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/6/c/6c7256d745ac4274c74ed0508862fb0a30cae47f.jpeg)

```python
# What eldritch artifacts are these? Don't let them blast you!
# The ice gate will open when both ogres are defeated.
def commandPalatt():
    armyExit=Vector( 78,40)
    paladin=hero.findByType('paladin',hero.findFriends())
    witch=hero.findByType('witch',hero.findEnemies())
    chieftain=hero.findByType('chieftain',hero.findEnemies())
    if paladin and paladin.canCast("heal", paladin) and paladin.health<paladin.maxHealth*0.8:
        hero.command(paladin,'cast','heal',paladin)
    elif witch and paladin:
        hero.command(paladin, "attack", witch)
    elif witch and chieftain:
        hero.command(paladin, "attack", chieftain)
    elif paladin:
        hero.command(paladin, "move", armyExit)

def commandRest():
    armyExit=Vector( 78,40)
    chieftain=hero.findByType('chieftain',hero.findEnemies())
    soldiers=hero.findByType('soldier',hero.findFriends())
    archers=hero.findByType('archer',hero.findFriends())
    for soldier in soldiers:
        if soldier and chief:
            hero.command(soldier, "attack", chief)
        elif soldier and witch:
            hero.command(soldier, "attack", witch)
        elif soldier:
            hero.command(soldier, "move", armyExit)
    for archer in archers:
        if archer and chief:
            hero.command(archer, "attack", chief)
        elif archer and witch:
            hero.command(archer, "attack", witch)
        elif archer:
            hero.command(archer, "move", armyExit)
    

enemies=hero.findEnemies()
robots=[]
for enemy in enemies:
    #hero.say(enemies[7].type)
    #hero.say(enemy.type[0:5])
    if enemy.type[0:5]=='robot':
        robots.append(enemy)
    
midX=(robots[0].pos.x+robots[1].pos.x)/2  
midY=(robots[0].pos.y+robots[1].pos.y)/2  
#hero.say('x: '+midX +" y: "+midY)

midPoint=Vector(midX+2,midY)
while hero.posx<midPoint.x-2:
    hero.move(midPoint)
    

iceGatePos=Vector(61,15)
#while hero.pos!=iceGatePos:
# hero.move(iceGatePos)
armyExit=Vector( 78,40) 

    
    
#heroExitPos=Vector(78,14)
enemyMissile = hero.findNearest(hero.findEnemyMissiles())
while True: 
    iceGateVectorFromHero=Vector.subtract(iceGatePos,hero.pos)
    iceGateVectorFromHero=Vector.normalize(iceGateVectorFromHero)
    iceGateVectorFromHero=Vector.multiply(iceGateVectorFromHero,5)
    enemyMissile = hero.findNearest(hero.findEnemyMissiles())
    if enemyMissile:
        distToEM=hero.distanceTo(enemyMissile)
        #hero.say(distToEM)
        if distToEM<5:
            missileAttackVector=Vector.subtract(hero.pos,enemyMissile.pos)
            missileAttackVector1=Vector.normalize(missileAttackVector)
            missileAttackVector5=Vector.multiply(missileAttackVector1,5)
            #hero.say(missileAttackVector)
            goal=Vector.add(missileAttackVector5,iceGateVectorFromHero)
            pass
        if enemyMissile:
            moveToPos=Vector.add(hero.pos,goal)
            hero.move(moveToPos)
    commandPalatt()
    commandRest()

```

---

<div class="post-metadata">

**Author:** ![FalconX11\_312](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/falconx11_312/32/26330_2.png) [@FalconX11\_312](https://discourse.codecombat.com/u/FalconX11_312)\
**Post date:** [September 5, 2021, 10:12am UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/2 "2021-09-05T10:12:39Z")

</div>

I don’t have BS4 now but when I did, I didn’t pass `paladin` as a second parameter in the if-statement. Try removing it.

---

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [September 5, 2021, 12:51pm UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/3 "2021-09-05T12:51:37Z")

</div>

> [@charliefik](#):
>
> ```python
> paladin=hero.findByType('paladin',hero.findFriends())
> witch=hero.findByType('witch',hero.findEnemies())
> chieftain=hero.findByType('chieftain',hero.findEnemies())
> 
> ```

All these return a list, if you want to try to do something like `attack()` or `canCast` while using them as a parameter, it will throw an error.  
You must put a [0] to turn it into one enemy.

---

<div class="post-metadata">

**Author:** ![charliefik](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@charliefik](https://discourse.codecombat.com/u/charliefik)\
**Post date:** [September 5, 2021, 12:53pm UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/4 "2021-09-05T12:53:34Z")

</div>

I was being an idiot. I thought that because there was just 1 paladin it would return a single item. But it’s still an array.

I haven’t tried your solution out yet but I’m sure you’re right

---

<div class="post-metadata">

**Author:** ![charliefik](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@charliefik](https://discourse.codecombat.com/u/charliefik)\
**Post date:** [September 5, 2021, 12:57pm UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/5 "2021-09-05T12:57:36Z")

</div>

I did the same thing for witch and chieftain. Normally after doing a find I’ll loop through with a for next and don’t usually think of finding a single one at a time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [September 6, 2021, 12:57am UTC](https://discourse.codecombat.com/t/paladin-cancast-heal-paladin-paladin-has-no-method-cancast/30342/6 "2021-09-06T00:57:52Z")

</div>

Closed on September 6, 2021, 12:57am UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
