Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Endangered Burl trouble

    enemy = self.findNearestEnemy()
    # Remember: don't attack type "burl"!
    if enemy.type is "burl":
        self.say("I'm not attacking that Burl!")

    # The "type" property tells you what kind of creature it is.
    if enemy.type is "munchkin":
    # Use "if" to attack a "thrower".
    if enemy.type is "thrower":
    # If it's an "ogre", run away to the village gate!
    if enemy.type is "orge":
        self.moveXY(40, 47)

Whats wrong with my code? I have spent a lot of time, trying to figure this out. I have read other forums posts and they do not make sense.


What is the error that is happening? The code does look pretty good to me… The only possible issue I see is that you are attacking twice for munchkins and throwers. Better would be to only attack once each time through the loop, in case the first attack kills them.


Whats the error? could enemy be None?


Ah, I see it: you have “orge” instead of “ogre”.


Also, remember that not always self.findNearestEnemy() will return an enemy (sometimes there isn’t any). In that case your code would fail to find an enemy.type.


@Roberto - The code won’t fail as he has it designed, for this particular level. I just checked the level (and my successful code), and there are always enemy Burl around. However, normally, it is great practice to have if enemy before the enemy.type checks. I do agree on a general basis.