[SOLVED] How to beat chameleons

MY CODE

while True:
    greenFlag = hero.findFlag("green")
    if greenFlag:
        hero.pickUpFlag(greenFlag)
    else:
        if enemy:
            enemy = hero.findNearestEnemy()
            hero.attack(enemy)
        else:
            pass

MY HERO ONLY COLECT THE FLAG IT DOSENT FIGHT

I think that you should delete this else.

Andrei

It still doesn’t work

You need to define ‘enemy’ before using it in an if statement.

1 Like

what dose that mean.

The statement ‘if enemy’ will forever be False, because you don’t define ‘enemy’ until the line after…reverse these two lines, instead.

1 Like

I got it thanks :grin: :heart_eyes: :heart_eyes:

1 Like

Then congratulations for completing the level! :partying_face:

Andrei

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.