Summit's Gate error?


So, the Beam Towers are type tower, right? Well, I am telling my minions to ignore the Beam Towers, but they still attack them anyway. Here is the code I use it ignore certain things:

def removeByType(array, excludedType):
    tempArray = []
    for enemy in array:
        if enemy.type is not excludedType:
    return tempArray

And here is the code line:

enemy = paladin.findNearest(removeByType(self.findEnemies(), "tower"))

Can you tell me what I am doing wrong?


I’m not 100% sure, but I believe you check if excludedType is truthy, negate that and check if enemy.type is falsy (aswell):

if enemy.type is not excludedType:


if enemy.type is not truthy(excludedType):


if enemy.type is falsy(exludedType):

You may want to check this instead:

if not (enemy.type is excludedType):

Python is [AWESOME][1]

def removeByType(array, excludedType):
    return [enemy for enemy in array if not (enemy.type is excludedType)]

enemies = removeByType(self.findEnemies, "tower")

#or even shorter

nearestEnemy = paladin.findNearest([e for e in self.findEnemies if not (enemy.type is excludedType])

but the last one is kinda not intuitive…


Nope, still doesn’t work. Minions continue to commit suicide by Beam Tower. However, it does work in Pesky Yaks, which is where I got the function from.


If I say the types, they are “tower” and your removeByType function seems to work for me, my guys ignore the towers and attack other stuff.

Maybe you need to reload/refresh it. Did you load the level before it came out in the email?

If you have the twilight glasses you could:


first thing, and it should tell you the two towers…


Also I just checked, my approach definitely works for sorting out the towers.

Just an idea:

If the towers are to big of a problem, try to use the catapults against them (hardcore-way, not recommended).


Oh, I have the problem now! I was overriding the removeByType by using it again for doors! Thanks!


Okay this a problem for my code on summits gate I am hitting the hard execution limit I don’t see the infinite loop and any help with this level would be appreciated here is my code

    i = 0;
    friends = this.findFriends();
    while (i < friends.length) {
        friend = friends[i];
        this.command(friend, "attack",enemy);

PS I know this code is not really efficient

while i < = > something:
    must contain increment/decrement of i


oop silly me thanks @Vlevo


I need help with summits gate

This is my code:

enemy = self.findNearest(self.findEnemies())
i = 0
friends = self.findFriends()
while (i - friends.length):
friend = friends[i]
self.command(friend, "attack",enemy)

IT says I have a slow or infinte loop


Hello, sourish, and welcome. Please read the FAQ prior to your next post, so that you can learn how to properly format your code. I’ve done it for you this time, but please do so yourself in the future.

You need to use proper indentation levels. With them as they are, they will always result in an infinite loop. Additionally, the line while (i - friends.length): will always evaluate as True, and so comes out as while True:. This is a infinite loop. I think you meant while i < friends.length:. Don’t forget to increment i at the end.


thankyou ChronistGilver. can you please post my code with the correction because I do not understand what you mean. Thanks in advance
Right now this is my code:

enemy = self.findNearest(self.findEnemies())
i = 0
friends = self.findFriends()
while i < friends.length:
    friend = friends[i]
    self.command(friend, "attack",enemy)


I’d like it if you were to understand it yourself. That way you’ll learn more. Put it this way:

while i - friends.length:

The problem with this line of code is that i-friends.length is a statement. Since this statement will always come out as a number, and therefore exists, the statement itself is True, so the while-loop becomes while True. This statement is an infinite loop, which gives you your error. A better alternative is to only loop over your friends. Use while i < friends.length:.

You never increment i, that is, change the value of i, at the end of the loop. This means that you will always be commanding only one friends. Increment i at the end of the loop.


How do I increment i at the end of the loop
can you give me the increment of i for my code at the end of it

i = i + 1

or short:

i += 1


is this the right code because it is not working

 enemy = self.findNearest(self.findEnemies())
 i = 0
 friends = self.findFriends()
 while i < friends.length:
        friend = friends[i]
        self.command(friend, "attack",enemy)
        i = i + 1

I need more help guys
But I still appreciate your effort to help me


The code looks OK, but there is no indenting - remember, python requires that you indent things properly - so that may be the problem:

enemy = ...
while ...:
    i = i + 1

Also, I don’t know if friends.length is correct, or you have to use len(friends) instead.


I did’t really get what you meant


And plus it didn’t work when I corrected this:

while i < friends.length:


while i len(friends):


I also didn’t get what this meant:

enemy = …

while …:

i = i + 1