Nalfar cryptor spells

Hello can someone explain to me what this code means, I’m new to Nalfar Cryptor and I need some guides on some of his spells.


pet.moveXY(25,70)
def shouldIUsePoison():
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy and hero.distanceTo(enemy)>10 and hero.distanceTo(enemy)<=30:
            return enemy
def DIE(enemy):
    if hero.distanceTo(enemy)<=15:
        hero.cast("drain-life", enemy)
    elif hero.distanceTo(enemy)<=45:
        hero.attack(enemy)
while True:
    hero.moveXY(87, 71)
    if hero.canCast("raise-dead"):
        corpses = hero.findCorpses()
        if corpses.length>5:
            hero.cast("raise-dead")
    if hero.canCast("summon-burl"):
        hero.cast("summon-burl")
    if hero.canCast("summon-undead"):
        hero.cast("summon-undead")
    foes=hero.findEnemies()
    warlocks=hero.findByType("warlock",foes)
    witchs=hero.findByType("witch",foes)
    enemies=warlocks+witchs
    enemy=hero.findNearest(enemies)
    if enemy:
        DIE(enemy)
    else:
        fangriders=hero.findByType("fangrider",foes)
        throwers=hero.findByType("thrower",foes)
        shamans=hero.findByType("shaman",foes)
        enemies=fangriders+throwers+shamans
        enemy=hero.findNearest(enemies)
        if enemy:
            DIE(enemy)
        else:
            enemy = hero.findNearestEnemy()
            if enemy:
                DIE(enemy)
    should=shouldIUsePoison()
    if hero.canCast("poison-cloud") and should:
        hero.cast("poison-cloud", should)
    friends=hero.findFriends()
    if friends:
        BFF=friends[0]
        for friend in friends:
            if friend.health>BFF.health:
                BFF=friend
        if BFF and hero.canCast("sacrifice"):
            hero.cast("sacrifice",BFF)





Hi @iLuvCookies, Welcome to the CodeCombat Discourse! :tada:
You could check out this topic:

If you have any more questions about specific spells please ask.
Danny

2 Likes

What does for enemy in enemies: and if corpses.length > 5: means thanks

The first one (for enemy in enemies) loops over all of the enemies and call each one of them enemy (the for loops are explained in the mountain) and the second one (if corpses.length > 5) checks if the array corpses has 7 or more elements (if you use Phyton you can write len(corpses) instead of corpses.length). Do you understand?

Andrei

So these 2 codes are explained in the mountain, correct?

The for loops are for sure explained there. And the if statements are explained in the forest. And the arrays are explained in the desert.

Andrei

I’m in dessert currenly but I dont think ive learned it yet, I’ve just started Cubic Minefield, but I’m still confused what array is?

An array is a list, but you will also learn that in the next levels. :wink:

Andrei

1 Like

im still a little bit confused corpses.length, length is from one end to another, so it doesnt quite make sense

Think of it this way…hero.findCorpses() results in this:

corpes[0] = deadGuy1
corpes[1] = deadGuy2
corpes[2] = deadGuy3
corpes[3] = deadGuy4
…etc

In this case, the length of the array is 4. The line ‘if corpses.length > 5’ is testing to see if at least 6 or more corpses are available. This allows for maximum efficiency when casting “raise-dead”.

2 Likes

Thanks got it

If its a different code like if len(neutrals): does it mean the same thing?

Not sure I understand your question, but the default usage in PY is len(something). However, the other method, ‘something.length’ (which is default for JS) is also supported in PY.

What does while itemIndex < len[items] means

It means pretty much what the statement says (python is sometimes very like english):
while-itemIndex-is-less-than-the-amount-of-items: ----Then do something:
itemIndex is a variable probably with an integer value (whole number 1,2,3) And items is an array of items.
Normally at the end of the code inside one of those loops you would increment (increase by one) itemIndex, so that the code loops through the exact same amount of times as the number of coins you have.
Danny

1 Like