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

Quiz: Issuing successive commands

Question A: Will the paladin heal oneself?
case 1:

        if paladin.health < paladin.maxHealth and paladin.canCast("heal"):
            hero.command(paladin,"cast", "heal", paladin)    
        hero.command(paladin, "move", {"x":paladin.pos.x + 3, "y":paladin.pos.y})

case 2:

        hero.command(paladin, "move",  {"x":paladin.pos.x + 3, "y":paladin.pos.y})  
        if paladin.health < paladin.maxHealth and paladin.canCast("heal"):
            hero.command(paladin,"cast", "heal", paladin)

Question B: How to do the two cases right?

Both cases look valid, it just depends on if you want your paladin healed before he moves, or after.

@dedreous : Both cases are invalid, but strangely one of them is working and I don’t know why. :face_with_raised_eyebrow: Do you have Boss Star IV to summon Paladins?

No, you need the Boss Star V to do that (not available to users yet, only to the devs). BS IV however, does allow you to command Paladins tho.

Speaking of which, how are you defining your “paladin”? I tested your move code using one of the ‘1000 Flowers’ levels. I had to summon a soldier, instead of a paladin, but the move concepts are the same. My test soldier move where I told him to. However, it took me a couple of tries to get his definition correct.

I compared your paladin heal statement against one I used in another level and it looks fine.

That leaves the definition of your paladin…in my test, I used:

hero.summon("soldier")
paladins = hero.findFriends()
paladin = paladins[0]

There a many other ways to do this, but I went for the quick/easy way, since I knew I would be working with just the one friend.

Boss Star IV, test code & picture:

hero.moveXY(10, hero.pos.y)
hero.summon("paladin")
paladin = hero.findByType("paladin")[0]
while True:
    if paladin and paladin.health > 0:
        hero.attack(paladin)
        if paladin.health < paladin.maxHealth and paladin.canCast("heal"):
            hero.command(paladin,"cast", "heal", paladin) 
        hero.command(paladin, "move",  {"x":paladin.pos.x + 3, "y":paladin.pos.y}) 

lol…once I remembered to change weapons, your code worked fine. Of course, a soldier cannot heal, so that part is not truly tested yet.

For comparison, I borrowed code from ‘make-advances’:

                if friend.health <= friend.maxHealth / 2:
                    hero.command(friend, "cast", "heal", friend)

Of course, substitute ‘paladin’ for ‘friend’ here. Oh…and the ‘canCast’ part too.

There were so many errors in “Make advances” topic…So will the soldier attack the hero?

hero.moveXY(10, hero.pos.y)
hero.summon("soldier")
soldier = hero.findByType("soldier")[0]
while True:
    if soldier and soldier.health > 0:
        hero.attack(soldier)
        if soldier.health > soldier.maxHealth/3 and  soldier.health < soldier.maxHealth/2:
            hero.command(soldier,"attack", hero) 
        hero.command(soldier, "move",  {"x":soldier.pos.x + 3, "y":soldier.pos.y}) 

Oops, I just realized I was incorrect on the summon paladin point…obviously, IV does give that ability. There was a thread about that, somewhere, and I mis-remembered.

Unless you command him to do so, he should not.

When I run the code, I follow the paladin all the way to the east edge and keep attacking until he’s dead, taking no damage myself.

And replacing with:

        hero.command(soldier, "move",  {"x":soldier.pos.x + 3, "y":soldier.pos.y})         
        if soldier.health > soldier.maxHealth/3 and  soldier.health < soldier.maxHealth/2:
            hero.command(soldier,"attack", hero) 

What do you get? Are these the results you have expected?

Staying with ‘paladin’, yes it performs as expected. Once the paladin got below 300 and stayed above 200, he’d swing back and attack.