I need help for Summits Gate!

You may be issuing them a move command every game frame.
The loop block is only executed one per game frame so issuing a command in the next loop will not generate a problem.
But if you have

loop{
this.command(friend,"attack",enemy);
this.command(friend,"move",pos);
}

Then the move will overwrite the attack command and the friend will only move. He can only follow one order during each game frame.

I’m giving no orders, yet all troops move to the nearest enemy waiting to be slaughtered.

By default they are attacking the nearest enemy, not moving. Save your code on a file somewhere, then click the reload code button on the level. Check if they are still only moving.

here is my code. It says on line 19 Unexpected indent.I cant get thrugh the inner gate because I am Getting killed by orges.

loop:
        enemy = self.findEnemies()
        friends = self.findFriends()
        friendIndex =0
        for friend in friends:
            self.command(friends[0], "move", {'x':92, 'y':8})
            self.command(friends[1], "move", {'x':92, 'y':60})
        self.moveXY(87, 33)
        self.attack("Inner Gate")
        enemy = self.findNearest(self.findEnemies())
        if enemy:
             self.attack(enemy)
        self.moveXY(132, 33)
        self.attack("Outer Gate")

@Doom You said there is an error on line 19, but you have posted only 12 lines of code. :stuck_out_tongue:
I’m not really sure, but it seems you have one extra space before self.attack(enemy) in the 12th line of the code you have posted above. Also, your entire loop seems to be indented twice as much as usual.

By the way, when posting code blocks, the ``` delimiters should go on their own line (put a line break before and after them). I fixed that for you.

Let me re Write.

there is no error, but Whwn I get to the Inner Gate I walk left>

        enemy = self.findEnemies()
        friends = self.findFriends()
        friendIndex =0
        for friend in friends:
            self.command(friends[0], "move", {'x':92, 'y':8})
            self.command(friends[1], "move", {'x':92, 'y':60})
        self.moveXY(87, 33)
        self.attack("Inner Gate")
        enemy = self.findNearest(self.findEnemies())
        if enemy:
             self.attack(enemy)
        self.moveXY(132, 33)
        self.attack("Outer Gate")```

Please add line breaks before and after both of the ```, otherwise the indentation and syntax highlighting does not show.

As for the code: remember that everything inside your loop repeats indefinitely. Currently, your code reads:

  1. Command friends to move somewhere.
  2. (Try to) move to 87, 33.
  3. Attack the inner gate once.
  4. Attack the closest enemy once, if it exists.
  5. (Try to) move to 132, 33.
  6. Attack the outer gate once.
  7. Repeat everything from step 1 and onward, indefinitely.

As you can see from the instructions above, the loop’s code will repeatedly move between certain positions between attacking enemies, which is not really what you want.

Note that this level requires killing every single enemy in the map, so I believe a better strategy would be to focus on a segment of the level at a time. Making a loop for each segment of the map does not seem like a bad idea. Once you can handle killing everything before the first gate, you can use flags or some smarter technique to detect when you should destroy the gate and progress further (you can use the break statement to break out of a loop and advance to the next one).

With all that said, Summit’s Gate is by far the hardest CodeCombat level if you are playing just the free campaign, in my opinion. Yeah, there are some pretty damn hard Glacier levels, but if you survive Summit’s Gate you will already know what to expect. The real problem is that Summit’s Gate is such a sudden steep difficulty increase in comparison to the previous levels.

Good luck and have fun! :smiley:

Thanks .I think I got it

I changed my code. And would CALTHROP BELT be good to buy and use?

I’m not sure, haven’t tried it on that level. I guess it depends on your strategy. :slight_smile:

What was your armor on that level

If I recall correctly, I had Sword of the Temple Guard, Worn Dragonplate, Worn Dragonshield, Viking Helmet, Compound Boots and Ring of Speed. I also remember that I had to do quite a few rounds of each of the “repeatable levels” (those levels with an yellow glow in the map that get harder each time you win) in order to afford all that gear. :smile:

Nowadays, though, CodeCombat has added a bunch of new achievements, so it should be much easier to afford this gear by that point now.

I don’t know what’s wrong.It just says “Possibly a bug with advanced Python feature parsing”.

    enemy = self.findNearestEnemy()
    if enemy:
        self.attack(enemy)
    if enemy < 1:
        break
loop:
    if  type = "tower":
        self.attack("Inner Gate")
    if "Inner Gate".health < 0:
        self.moveXY(170, 33)
        break
loop:
    flag = self.findFlag()
    if flag:
        self.pickUpFlag(flag)

This line:

if  type = "tower":

Should be:

if type == "tower":

Use two equal signs for comparison, one for assignment.

(the “advanced feature parsing” is about assignments inside of conditional expressions, but that is usually considered a bad/confusing practice and not recommended for beginners, so CodeCombat not supporting it is not really that bad. The error message could be a bit more specific, though.)

Thankyou but now it is saying type isn’t defined and how do you def “type”?

Never mind but now my men is enloped in the big red x and I dont do anythn.It doesnt tell whats wrong.

    enemy = self.findNearestEnemy()
    if enemy:
        self.attack(enemy)
    if enemy < 1:
        self.attack("Outer Gate")
        break
loop:
    def Type(type):
        if  type == "tower":
            self.attack("Inner Gate")
        if "Inner Gate".health < 0:
            self.moveXY(170, 33)
            break
loop:
    flag = self.findFlag()
    if flag:
        self.pickUpFlag(flag)

I can see quite a few problems in that code.
It is pretty late here and I’m too tired, but I should be able to outline a few issues:

if enemy < 1:

Enemy is an unit object, it does not make much sense to compare it with a number. Did you mean to check the number of enemies left? You will need to check the length of a list of enemies, e.g.:

if len(self.findEnemies()) < 1:

In your other loop, you are defining a “Type” function but never calling it. Perhaps you did not mean to define a function, but rather use enemy.type?


Another problem here:

if "Inner Gate".health < 0:

You trying to get check the “health” of a string. That is not going to work. You need to get a reference to the inner gate unit (“Thang”) object somehow.


There are probably other issues, but a word of advice that should help on this level: try to think of the solution first, only then start writing the code. This way you may have a far easier time in this level than writing the first thing that comes to your mind.

for enemy.type i put
def enemyType(type):
and for

if "Inner Gate".health < 0:

I dont understand

As mentioned, “Inner Gate” is a string. First find the object corresponding with the string:

innerGate= None
for enemy in enemies
    if enemy.id == "Inner Gate":
        innerGate = enemy
        break

It says code needs to line up on line 5 on this part of the code

enemy = self.findNearestEnemy()
def enemyType(type):
    if  type == "tower":
        innerGate= None
        for enemy in enemies
            if enemy.id == "Inner Gate":
                innerGate = enemy
                self.attack("Inner Gate")```