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

Sarven Road moving problem


So I’ve been trying to complete the Sarven Road level for a few days now and nothing seems to be working. Here’s my code:

enemies = self.findEnemies()
x = self.pos.x
y = self.pos.y
for enemy in enemies:
        if enemy:
            self.moveXY(x + 10, y + 10)

The problem is my hero isn’t moving. Weirdly, I’ve tried some other stages but he still doesn’t move.

Thanks - Finn


You shouldn’t be using a for loop at this point. To find an enemy you should:

enemies = self.findEnemies()

The problem is that you are going through all the enemies and if they are not an enemy you will move.
Everything in enemies is an enemy, so you will never move.

Delete for enemy in enemies:


Better start from scratch, the world updates will still be outside the loop.
Basically you code should be like:

    update world view - find enemies, own position, items, etc.
    #react to the info you just got
    if (enemy)
          attack enemy


Your not defining enemy You need to use the self.findNearest() command and define enemies in the ()

enemies = self.findEnemies()
enemy = self.findNearest(enemies)


All finished now, thanks for everyone’s help!