Enemy = Null, filter confusingly functioning (Solved)


#1

When I run:

enemies = hero.findEnemies()
if enemies:
    hero.say("Enemies")

The result is Hero saying “Enemies” when there are no enemies. Why does the if enemies not filter?
if I run:

enemies = hero.findEnemies()
if enemies:
    for enemy in enemies:
        hero.say("enemy")

Then my Hero says the names when there are actually enemies. Any Ideas?
-Thanks


#2

What is hero.findEnemy ?

If you wanted to write hero.findEnemies, then without brackets it’s a function.

bool(function) is True

#3

Oh, that was a typo in my post, not code.


#4

Got it. There is a problem with python interpretator and it works like in JS.
So the empty array is true in conditionals.
Try to check
if enemies.length:


#5

Thank you! This issue has been plaguing me :slight_smile: