A level I am struggling at. "Sarven Sentry."


#1

Hey. I am having a struggle on a level called “Sarven Sentry.” The goal is to fence out the yaks, but to kill the ogres. Here is my code.

loop:
     flagGreen = self.findflag("green")
     flagBlack = self.findflag("black")
if flag:
  if flagGreen:  
          self.pickUpFlag()
          self.buildXY("fence", flagGreen.pos.x, flagGreen.pos.y)
 if flagBlack:
          self.pickUpFlag()
          self.buildXY("fence", flagBlack.pos.x, flagBlack.pos.y)
else:
     self.moveXY(43, 31)

The things I noticed is that my hero is not moving anywhere. I also did not see any error when I typed this code. Can you help me on this?


#2

Flag is null because you are not assign it (flag=…) anywhere in your code
So if(flag) always fails

Use continue to skip at the end of the loop:

loop:
    if  situation1:
         do something 
         continue
    if situation2
         do something else
         continue
.  #and so on ..............................
   nothing special happens do boring stuff here
#end of loop

#3

I have an error saying to pass a flag object to pick up. What does that mean.


#4

That could mean that you need to specify the flag to pick up, for example:

if flagGreen:
    self.pickUpFlag(flagGreen)

#5

I DID IT! Thanks Zuf!