Sarven Road moving problem


#1

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:
    loop:
        if enemy:
            self.attack(enemy)
        else:
            self.moveXY(x + 10, y + 10)
        pass

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

Thanks - Finn


#2

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

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

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:


#3

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

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

#4

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

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

#5

All finished now, thanks for everyone’s help!