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

[SOLVED] Help on Kelvintaph Defiler

This is my code so far. But it all stops when step is made 2. What am I doing wrong?

# The ogres are trapping you with their dark rituals!
# Your hero can't do anything besides command and move without angering the warlocks.
# Beware ice, robots, traps, antigravity fields, and other dark magic.
# Somehow, you'll need to defeat Nalfar and save your paladin.
# The great treasure of Kelvintaph awaits your victory.
def commandPaladin(paladin):
    if hero.time >= 2:
        if paladin.canCast("heal") and paladin.health < paladin.maxHealth * 0.7:
            hero.command(paladin, "cast", "heal", paladin)
        else:
            hero.command(paladin, "shield")
    

def commandArcher(friend):
    if step == 1:
        enemy = friend.findNearestEnemy()
        if enemy and enemy.type != "yeti":
            hero.command(friend, "attack", enemy)
    elif step == 2 and friend.id == "Mirana":
        hero.command(friend, "move", {"x":9, "y":77})
    elif step == 2:
        hero.command(friend, "move", {"x":28, "y":49})

    
def commandSolider(friend):
    if hero.time >= 3:
        if hero.time <= 7:
            hero.command(friend, "move", {"x":21, "y":73})
        elif hero.time <= 9:
            enemy = friend.findNearestEnemy()
            if enemy and enemy.type != "yeti":
                hero.command(friend, "attack", enemy)
        elif hero.time == 10:
            step = 2
    elif step == 2:
        hero.command(friend, "move", {"x":24, "y":66})

def commandAllies():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        elif friend.type == "archer":
            commandArcher(friend)
        else:
            commandSolider(friend)
step = 0
hero.move({"x":32, "y":17})
#hero.cast("invisibility", hero)
while True:
    if hero.time == 2.2:
        step = 1
    commandAllies()


2 Likes

I would define the step variable in your while true loop. So have a series of ifs and then an elif checking hero.time then setting step to the appropriate number. You can then check step while commanding your friends without defining it each time.
I hope this helps,
Danny

4 Likes

So if I do that, my code will work?

3 Likes

Think of it as a suggestion, not a solution…we’ll never know until you at least try it :wink:

6 Likes

Ok. I will try it. :slight_smile:

3 Likes

Thanks for advice. I finished the level

3 Likes

Now I got the bonus. I am so happy! Thanks for help! :slight_smile:

3 Likes

3 Likes

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