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

Lvl. 5 ch.2 SOLVED


I wrote this code but system doesn’t accept it, says that it’s an error in the if statement

enemy = self.findNearestEnemy()
if enemy:

It worked when I retried today. Probably it was just a bug. -.-


Hello, Rijechanin, and welcome. Please format your code according to the FAQ.

You code looks sound. What is the error you get?


What you want to express (“if there’s any enemy”) is equivalent to what you coded (“if there’s a nearest enemy”). So basicaly, and as ChronistGilver said, your code is ok.

If you want to specifically use the “there is any enemy” statement, you can code it this way :

(self.findEnemies().length > 0)

or even


which means “the number of enemies is greater than zero” i.e. : “there is at least one enemy”

For example :

  if self.findEnemies().length :

But personally, i like your original code better…


Thanks, I changed it.


Thank you for explanation. I passed the level with my code.
Maybe the bug was created because I ereased comments…