CodeCombat is being weird And Sacrifice is not working


#1

It gives me this error for no reason


#2

When i take out the sacrifice it works perfectly fine


#3

Even when i put

if nearest and nearest.type == "soldier" and hero.isReady("sacrifice"):
   hero.cast("sacrifice", friend, hero)


#4

even when i do this


#5

(2nd one)When you place that line, it would check for the nearest’s type, even when nearest does not exist.

(3rd one) For every line which is for the cooldown to attack the enemy or against the enemy, place elif after the first cooldown for which is against the enemy, as it will then start from the beginning and check if the enemy exists.

In the first one, you didn’t check if nearest exists.

In short, you had flaws on every single one of them.


#6

So what would i put?


#7

I put this but it still is not working

        if friend:
            if friend.type == "soldier" and hero.isReady("sacrifice"):
                hero.cast("sacrifice", friend, hero)

#8

This is what happenes now. I fixed it. It stops loading


#9

you don’t need the if friends: line. And it is better if you don’t put it in the if enemy: line. And, you don’t need to check if friend exists when you put in a for loop in hero.findFriends().