Can't find shaman. What is wrong with my code?


#1

Why can’t find a shaman with my code? I think the problem is with the “or”, but not very sure… Any idea? I have to say that I can find the rest of enemies.

loop:
    flag = self.findFlag()
    enemy=self.findNearestEnemy()
    
    if flag:
        self.moveXY(flag.pos.x, flag.pos.y)
    elif enemy: 
        if enemy.type is "ogre" or enemy.type is "thrower": 
            self.say(enemy.type)
            if self.isReady("cleave"):
                self.cleave(enemy)
            else:
                self.attack(enemy)
        elif enemy.type is "scout" or enemy.type is "shamam":
            self.say(enemy.type)
            if self.isReady("cleave"):
                self.cleave(enemy)
            else:
                self.attack(enemy)

#2

I got it. You “shaman” is shamam. That should be it.

Hope this helps!

Endercore79


#3

That was quick, thanks! But actually in my code I wrote it right. Any other ideas??


#4

Hi,

Try using == instead of is.


#5

Nothing. The problem seems to be in the detection of the shaman. Any other idea?


#6

Have you tried with pickup flag ?


#7

Yes, I considered that the problem might be that the shaman was very far away to be detected. But it is not the case…


#8

This is very weird (could it be a bug?). The thing is that when I change the order it seems to find the shaman. That is it works with "

elif enemy.type is "shaman" or enemy.type is "scout":

but not with

elif enemy.type is "scout" or enemy.type is "shamam":

Any idea what is it going on? Could it be a bug?


#9

You wrote “shamam” again.

Please review your code thoroughly. You might think you wrote it correctly, but you never know.

In fact, I suggest you just delete that line entirely, and rewrite it from scratch. No Copy/Pasting. Copy/Paste guarantees that you repeat any mistakes made from the source.

What I said may sound a bit rude, but do it anyways. If it solves the problem, great! Problem is gone.
If it doesn’t then the underlying problem may be much more complex than we think.