The Dunes: Self frozens while throwers

Hello,

I am playing the dunes now, and everything works fine, except when a thrower appears in screen. Then self does not continue to other sentences until the thrower is dead.

Here is my code:

loop:
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if enemy:
        if enemy.type is 'sand-yak' or enemy.type is 'burl':
        # Don't fight Sand Yaks or Burls! Just keep collecting coins.
            pass
        # But if the enemy is a 'thrower' or an 'ogre', fight them.
        elif enemy.type is 'thrower' or enemy.type is 'ogre':
            if self.distanceTo(enemy) < 30: 
            #To keep collecting while the enemy is far
                if self.isReady('cleave'):
                    self.cleave(enemy)
                    
                elif self.isReady('bash'):
                    self.bash(enemy)
                
                else:
                    self.attack(enemy)
            else:
                pass #I think the problem is here
    elif item:
        # Collect coins.
        self.say('collecting') #To check if the action is taking place
        pos=item.pos
        X=pos.x
        Y=pos.y
        self.moveXY(X,Y)

The funny thing is that self does not do anything when a thrower appears if I delete the sentence self.say(‘collecting’) or if I change the distance to enemy necessary to start attacking.

Thanks!

Does it work for ogres?

It works for ogres as long as self.say() is active.

I know it does not make any sense…

I think you need to consider what happens if there is an enemy thrower or ogre, but they are more than 30 meters away. In that case you’re code won’t do anything I think. With the ogres they will eventually get close enough, but maybe not for the throwers?

So, I retested your code myself and I found its a problem that has to do with your

  if self.distanceTo(enemy) < 30: 

It’s because it takes notice of your enemy and you haven’t commanded it to do anything if the enemy is > 30 units. I am not sure if the

 else:
     pass #I think the problem is here

effects anything but that’s all the help I could find.

Yep. Moving

self.distanceTo(enemy) < 30:

to the line above will help.

Also, cleave isn’t needed in this level. It actually detracts away from the purpose of the level :smile:

Ok, solved after changing the pass to collecting items and deleting cleave and bash.

Is not also possible that the code was too complicated and it took to much time to think?

Thank you very much!! :smiley:

I had to simplify my code (as well as reposition run-order of certain commands) when I did this level at a previous point. There was too much ‘code’ happening, and it was taking too much time to think, thus delaying the actions of my hero, and not allowing me to pick up enough coins within the allotted time-frame.