Help about level- the dunes


#1

run out of time. help?

    # Collect coins. Ignore sand yaks and burls. Fight throwers and ogres.
loop:
    enemy = self.findNearest(self.findEnemies())
    item = self.findNearest(self.findItems())
    if enemy:
            if enemy.type is "thrower" or enemy.type is "ogre" :
                self.attack(enemy)
                self.moveXY(39, 39)
            else:
        # Collect coins.
                    item = self.findNearest(self.findItems())
                    if item:
                        yitem = item.pos.y
                        xitem = item.pos.x
                        self.moveXY(xitem, yitem)
                    else :
                        self.moveXY(39, 39)

#2

You are only collecting coins when enemy is not thrower/ogre…
(and not when there is no enemy)


#3

still the same problem


#4
if not enemy:

nothing will happen.
think of this as well


#5

Hi everyone I have a problem with this level it keeps telling me that there is an error with line 4 which is undefined and my hero won’t move. It seems strange as this line of code is what you start of with

loop:
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if enemy:
        if enemy.type is "sand-yak" or enemy.type is "burl":
         itemPos=item.pos
         itemx=itemPos.x
         itemy=itemPos.y
         self.moveXY(itemx,itemy)
      
            
            
     
        if enemy.type is "thrower" or enemy.type is "ogre":
            self.attack(enemy)
    elif item:
       itemPos=item.pos
       itemx=itemPos.x
       itemy=itemPos.y
       self.moveXY(itemx,itemy)

#6

Which line is it complaining about? “loop:”, "enemy = ", “item =”, “if enemy:”

Nothing looks wrong with, “loop:” or “if enemy:”, but I can think of a reason it might complain about the other two:

Which glasses are you using. Once you get to a certain type of glasses you can’t use “.findNearest____()” anymore but have to switch to using:

self.findNearest(self.findEnemies())
self.findNearest(self.findItems())


#7

Thanks for that. Changing the glasses did the trick!!!


#8

worked !!!