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:
tempArray.append(enemy)
return tempArray
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:
#becomes
if enemy.type is not truthy(excludedType):
#becomes
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])
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.
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);
}
[...]
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.
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