I need help with this code please.It involves cavern survival


enemy = self.findNearestEnemy()
flag = self.findFlag()
if flag:
if enemy:

        if hero.health < 200:
        if enemy.type is "ogre":    
            enemy = hero.findNearestEnemy()
            if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:

            For some reason it doesn't work please help

P.S I am using a ranger


You do not need to redefine enemy after line 9.


in addition to Hellenar’s point,
instead of:

if enemy.type is "ogre":


if enemy.type == "ogre":

also, I think you need to put () after hero.throwRange
EDIT - Whoops, hero.throwRange doesn’t take ().


I think that both is and == work the same.


is and == are actually different. is compares the two objects by reference and == compares their value. For example:

y = 99

if y == 99:

if 99 is "9" + "9":

Your hero will only say A because y equals to 99 as I defined in the line above. 99 is not “9” + “9” even though if you have your hero say (“9” + “9”), he will return 99 because you are combining to objects into one. So while they have the same facial value, they are two separate objects and changing one will object’s value will not affect the other.

Check out this stack overflow discussion if you are still confused: