Level: Sacred Statue and infinite loop of destruction!


#1

Hello everyone! I am a noob so don’t be too hard on me :smile:

Basically I wrote this for Sacred Statue:

def meatgrinder():
    enemy = self.findNearest(self.findEnemies())
    while enemy:
        if self.isReady("cleave"):
            self.cleave(enemy)
            enemy = self.findNearest(self.findEnemies())
        else:
            self.attack(enemy)
            enemy = self.findNearest(self.findEnemies())

meatgrinder()

loop:
    meatgrinder()
    if self.pos.x != 62 and self.pos.y != 67:
        self.moveXY(62, 67)

It was working quite well until half way it stopped and it told me I had failed the level. Before that it was giving me infinite loop errors but working at the same time. :frowning: I know it’s probably not the most elegant code in the world but it was getting the job done! What am I missing?


#2

first of all, your positioning System wont work.

if self.pos.x != 62 and self.pos.y != 67:
        self.moveXY(62, 67)

what if you are standing on (62, 100) ? Your character wont move, because x = 62 is True.

To the Infinite loop. Maybe its because you “real” Code is so short, that he is looping so quick that he thinks thats an Infinite.

Also, why are you calling “meatgrinder()” one time before your loop?


#3

An idea : If there is no enemy, and the position is correct, you’ll do nothing in your loop. So it’ll loop very fast.
Maybe you could try to add
else self.say(“Come on !”)
to wait enemies.