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
Bryukh
July 16, 2016, 4:08pm
2
What is hero.findEnemy
?
If you wanted to write hero.findEnemies
, then without brackets it’s a function.
bool(function) is True
1 Like
Oh, that was a typo in my post, not code.
Bryukh
July 16, 2016, 6:55pm
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:
2 Likes
Thank you! This issue has been plaguing me