Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Sarven Treasure - Python

I am trying to complete this level by having my character just run and pick up gold at first and then start fighting. All during this time I wan’t to be able to us a flag to tell my character to go to a teleporter. When I run the code it says "Hard execution limit of 3000000 reached? Any help or suggestions would be great. Thank you.

loop:
    items = self.findItems()
    item = self.findNearest(items)
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    green = self.findFlag("green")
    black = self.findFlag("black")
    violet = self.findFlag("violet")
    flags = self.findFlags()
    
    while self.health > 1000:    
        if item:
            self.moveXY(item.pos.x, item.pos.y)
        elif flags:
            if green:
                self.pickUpFlag("green")
                pass
    while self.health < 1000 and self.health > 500:
         if enemy:
            if self.distanceTo(enemy) < 10:
                if self.isReady("cleave"):
                    self.cleave(enemy)
                else:
                    continue
        elif item:
            self.moveXY(item.pos.x, item.pos.y)
        elif flag:
            if green:
                self.pickUpFlag("green")
                pass

what do you have
speed ring and softened leather boots are recommended
and also any good sword at least 200 damage

That means you have an infinite loop somewhere. Can you see any such loops in your code?
You might want to replace the parts with while self.health with if and else if.

You must update your world view (search for items, enemies, flags … inside each while loop
Otherwise will be stuck in the first while loop, you’ll pick the only item you searched for, and the do nothing until you run out of instructions.

An empty while loop will be executed a million of times in less than a fraction of a second.

OK thank you very much!

hey I know that u made this a while back but

flags = self.findFlags()
is not a command u need to remove the ‘s’ on the end of flags to be able to run the command

Howdy and welcome to the forum! Yes, it looks like Jacob has been inactive since he posted this.

Anyway, the statement he posted is actually correct, except that ‘self’ has been replaced with ‘hero’:
image
This method will find all flags of any color.

Otherwise, you can specify a color by:
hero.findFlag(“green”)