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

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

# 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()


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.

1 Like

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.

2 Likes

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

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.

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