Sarven Sentry Python help

flagGreen = self.findFlag("green")
flagBlack = self.findFlag("black")
flagViolet = self.findFlag("violet")
if flagGreen: 
    self.moveXY(flagGreen.pos.x, flagBlack.pos.y)
    self.buildXY("fence", self.pos.x, self.pos.y)  
 elif flagBlack:
    self.moveXY(flagBlack.pos.x, flagBlack.pos.y)
    self.buildXY("fire-trap", self.pos.x, self.pos.y)      
 elif flagViolet:

I can’t figure out why it is going wrong and not working. Could someone please help with this I can’t find the error.

please surround your code with three of these things ` so it’s easier to read (three above and three below the code)

if flagGreen: 
    self.moveXY(flagGreen.pos.x, flagBlack.pos.y)

something is not quite right here

Yes, as zimmah has said, surround your code with backticks, which is the key directly above the Tab key. See the FAQ for more information. I have formatted your code for you this time, but please do so yourself in the future.

Two things:
You have not surrounded your code in a loop.
Also, your elif statements are indented by one space. This should not be.

# Use different colored flags to perform different tasks.

while True:
    flagGreen = hero.findFlag("green")
    flagBlack = hero.findFlag("black")
    # If there's a flagGreen...
    if flagGreen:
        hero.moveXY(flagGreen, pos.x, flagBlack.pos.y)
        # Build a "fence" at flagGreen's position.
        hero.buildXY("fence", Xpos.x, Ypos.y)
        # Pick up the flag!
    # If there's a flagBlack...
    if flagBlack:
        # Build a "fire-trap" at flagBlack's position.
        # Pick up the flag!
    # Move back to the center.
        hero.moveXY(43, 31)

i dont know what to do .I cant understand.I cant keep on.why use (flagGreen, pos.x )as x and (flagBlack.pos.y) as y .

You haven’t defined Xpos, Ypos, or flag.

You don’t need that.

You should be building at flagGreen’s pos.x and pos.y

Build a “fire-trap” at flagBlack’s pos.x and pos.y then pickUpFlag() flagBlack.


Try look through the hints on the top right corner before asking more questions.
If you have any more questions after reading the hints section feel free to tell us your issue :smile:

1 Like