Help with summits gate codecombat[python]

Anyone help? here is my code:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat
her.
hero.cast("invisibility", hero)
while True:
    flag = self.findFlag("green")
    warlock = self.findNearest(self.findByType("warlock"))
    chief = self.findNearest(self.findByType("chieftain"))
    witch = self.findNearest(self.findByType("witch"))
    friends = hero.findFriends()
    if hero.time >= 67:
        break
    for friend in friends:
        if friend.type is 'paladin':
            if hero.health<1000:
                hero.command(friend, "cast", 'heal', hero)
    if flag:
        self.pickUpFlag(flag)
    if witch:
        self.attack(witch)
    if chief:
        self.attack(chief)
    if warlock:
        self.attack(warlock)
    else:
        enemy = self.findNearest(self.findEnemies())
        if enemy:
            self.attack(enemy)
hero.moveXY(184, 6)
hero.cast("invisibility", hero)
while True:
    def summonAndCommandArtillery():
        flag = self.findFlag("green")
    def avoidHazards():
        warlock = self.findNearest(self.findByType("warlock"))
    def findAndAttackEnemy():
        chief = self.findNearest(self.findByType("chieftain"))
    witch = self.findNearest(self.findByType("witch"))
    friends = hero.findFriends()
    hazards = hero.findHazards()
    for friend in friends:
        if friend.type is 'paladin':
            if hero.health<1000:
                hero.command(friend, "cast", 'heal', hero)
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    if flag:
        self.pickUpFlag(flag)
    if witch:
        self.attack(witch)
        summonAndCommandArtillery()
        avoidHazards()
    if chief:
        self.attack(chief)
        summonAndCommandArtillery()
    if warlock:
        self.attack(warlock)
        summonAndCommandArtillery()
    else:
        enemy = self.findNearest(self.findEnemies())
        if enemy:
            self.attack(enemy)
            summonAndCommandArtillery()

Hi InvincibileDude999,

Welcome to the forum!

We’re really keen to help people solve problems in their own code. However, ‘self’ was replaced by ‘hero’ several years ago in CoCo, so only people who’ve been around for a long time still use it hmmm? Perhaps you could have a go at writing your own code - look back at what you’ve learnt in previous levels, and think about the structure you need to overcome the obstacles.

Good luck!

Jenny

i havent completed this level yet but you have a her. and the start of your code

@jka2706, i have not been on codecombat for 5 years. I am only 8 years old and I tried a code from I need code for summits gate.

That is why people call coding a trial and error. You first start with your own code, then you run it and see what is wrong, you fix what is wrong, if you can’t fix it on your own, ask for some help. And you repeat the whole process again.
Lydia

2 Likes

OK, so let’s look at what you need to put in your own code:

  • Start off trying to solve the section before the first gate (leave the rest of the level for later).
  • Write a function for a friend to find and attack their nearest enemy
  • Write a function for a paladin to find the best person to heal, and if they can heal them.
  • Have a while True loop, and then inside this a for loop to go through each friend and command them.
  • Inside the while True loop, get the hero to find the catapaults and attack them.
  • Once all the enemies before the Outer gate are dead, break the while True loop, and think about the next section.

Hope that helps.

Jenny

2 Likes