[SOLVED] Drop the Flag Python Help!

i have been stuck on this level for a long time. I can’t figure out what is wrong in my code.

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

loop:
    flag = self.findFlag()
    if flag:
        # How do we get fx and fy from the flag's pos?
        # (Look below at how to get x and y from items.)
        
        
        self.buildXY("fire-trap", fx, fy)
        self.pickUpFlag(flag)
    else:
        item = self.findNearestItem()
        if item:
            itemPos = item.pos
            itemX = itemPos.x
            itemY = itemPos.y
            self.moveXY(itemX, itemY)
            
    topenemy = self.findNearestEnemy()
    bottomenemy = self.findNearestEnemy()
    rightenemy = self.findNearestEnemy()
    
    
    if topenemy:
        self.buildXY("fire-trap", 30, 45)
        
    if bottomenemy:
        self.buildXY("fire-trap", 30, 16)
    
    if rightenemy:
        self.buildXY("fire-trap", 30, 31)

can someon please tell me what i am doing wrong. Thx :smile:

You need to set fx and fy

You already have the flag. Can you think of a way get the position of the flag?


#Warning! Spoilers ahead!

Sadly it is currently not possible to combine spoilers and code-blocks, though here the unspoilerd code.

loop:
    if flag:
        fx = flag.pos.x
        fy = flag.pos.y
        self.build("fire-trap", fx, fy)
        self.pickUpFlag(flag)
    else:
        item = self.findNearestItem()
        if item:
            itemPos = item.pos
            itemX = itemPos.x
            itemY = itemPos.y
            self.moveXY(itemX, itemY)

i still didn’t get it. here’s the new code:

loop:
    flag = self.findFlag()
    if flag:
        fx = flag.pos.x
        fy = flag.pos.y
        self.build("fire-trap", fx, fy)
        self.pickUpFlag(flag)
    else:
        item = self.findNearestItem()
        if item:
            itemPos = item.pos
            itemX = itemPos.x
            itemY = itemPos.y
            self.moveXY(itemX, itemY)

The ogres won’t die.

i am supposed to defeat the ogres with traps.

Correct.
You happily collect all the coins. From time to time, an ogre will come along. You use your flag to place a fire-trap, and then continue to collect the coins. After some time, all ogres are defeated.

3 Likes

Thanks for your help. I appreciate it. :smile:

1 Like

i need help with same level

Please post your code and state the difficulty you’re having. Also, state any errors you’re receiving. We can’t help you if we don’t know what the problem is.

actually mind the trap

Please place assistance requests in the correct thread. You are requesting assistance with the level, Mind The Trap, in the thread for, Drop The Flag. If we all did this, this board would be a complete mess. Please either revive a previous thread for Mind The Trap or create a new one. Thank you.

I am stuck because my hero is not placing any traps when I remove the flags.

1 Like

What do you mean? Your code looks like my working code.

Andrei

Yeah I solved it I was just having trouble choosing the different flags to place down.

2 Likes

Then congratulations! :partying_face:

Andrei

1 Like

Can you now delete the code since it is a working code @Zoe_Witte?

Andrei

Thanks @Zoe_Witte! And congrats again!

Andrei

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.