Help: Drop the Flag

i keep getting a type error and i don’t know how to make it go away.

flag = self.findFlag()
if flag:
    self.buildXY("fire-trap", 30, 45)
    self.buildXY("fire-trap", 30, 31)
    self.buildXY("fire-trap", 30, 16)
else:
    item = self.findNearest(self.findItems())
    if flag:
        itemPos = item.pos
        itemX = itemPos.x
        itemY = itemPos.y
        self.moveXY(itemX, itemY)
    if item:
         self.findNearest(item)

my warning is this

delete this

add a moveXY statement after self.findNearest(item)
question: why are you using self? If this is not your code please write your own.

ok i will do that now

this is my updated code

flag = self.findFlag()
if flag:
    
else:
    item = self.findNearest(self.findItems())
    hero.moveXY(x, y)
    if flag:
        itemPos = item.pos
        itemX = itemPos.x
        itemY = itemPos.y
        self.moveXY(itemX, itemY)
    if item:
         self.findNearest(item)

delete this

delete this and again why are you using self.

what do i put where the else is? it said else must be paired with “if”

becase my hero has to do it

Dude look at what I said.

oh sorry i didnt see that part

now my hero is not moving
this is my updated code

flag = self.findFlag()
if flag:
    
    if flag:
        
        item = self.findNearest(self.findItems())
    hero.moveXY(x, y)
    if flag:
        itemPos = item.pos
        itemX = itemPos.x
        itemY = itemPos.y
        self.moveXY(itemX, itemY)
    if item:
         self.findNearest(item)

Try to rewrite the code then I’ll corect it.

what do you mean rewrite the code?

Reset the level, try to write the code again.

ok here it is
what do i do now

# Put flags where you want to build traps.
# When you're not building traps, pick up coins!

while True:
    flag = hero.findFlag()
    if flag:
        # How do we get flagX and flagY from the flag's pos?
        # (Look below at how to get x and y from items.)
        item = self.findNearest(self.findItems())
        
        
        hero.buildXY("fire-trap", flagX, flagY)
        hero.pickUpFlag(flag)
    else:
        item = hero.findNearestItem()
        if item:
            itemPos = item.pos
            itemX = itemPos.x
            itemY = itemPos.y
            hero.moveXY(itemX, itemY)

my hero is not placing any traps he is just going for the coins

You have to submit then place flags.

i did do that and he is going for coins

show a screen shot
200

ok i will do that now