Drop The Flag Level Help


#1

Hey Guys I’m new to code combat I just started playing yesterday and I need help on Drop The Flag Level.
I don’t understand this flag code at all. Can somebody help me please? I fan
This is the original code and somebody help me

# 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?
        
        
        self.buildXY("fire-trap", fx, fy)
        self.pickUpFlag(flag)
    else:
        item = self.findNearestItem()
        if item:
            pos = item.pos
            itemX = pos.x
            itemY = pos.y
            self.moveXY(itemX, itemY)

How do you complete the level Drop The Flag?
Drop The Flag Help!
#2

Is this what you are missing?

flagpos = flag.pos
fx = pos.x
fy = pos.y


#3

So do I just add the code or edit some of it?


#4

Add some code in there after the comment saying # How do we get fx and fy from the flag's pos? to define the fx and fy variables.


#5

This is what I have so far but it doesn’t seem right.

loop:
    flag = self.findFlag()
    if flag:
        # How do we get fx and fy from the flag's pos?
        flagpos = flag.pos
        fx = pos.x
        fy = pos.y
        
        
        self.buildXY("fire-trap", fx, fy)
        self.pickUpFlag(flag)
    else:
        item = self.findNearestItem()
        if item:
            pos = item.pos
            itemX = pos.x
            itemY = pos.y
            self.moveXY(itemX, itemY)

#6

Dang it still doesn’t work ;-; this is the toughest 1 I had ever


#7

Is that the only code I need to add


#8

You set flagpos = flag.pos, but then you try to read pos.x instead of flagpos.x, which happens to be the pos you defined in the else as item.pos. Tricky bug!


#9

Can u show me an example of the code like
lines
up
like
this


#10

I don’t want to just give you the answer! But if you describe what errors you see or what parts aren’t working, I can point out what to try next.


#11

I know but here’s the thing I don’t even get flag coding like at all.


#12

When you drop a flag after hitting submit, you can have your hero respond to that flag. The pickUpFlag method moves to the flag and removes it. If you want to build a fire-trap where the flag is, though, you need x- and y-coordinates for the buildXY method. So this level is getting you used to accessing flag.pos.x and flag.pos.y so that you can pass those coordinates to the buildXY method, which lets you build the fire-trap where the flag is. After you build the fire-trap, you can use pickUpFlag to clear the flag and keep collecting coins.

That’s what this section does:

  if flag:
        # How do we get fx and fy from the flag's pos?
        flagpos = flag.pos
        fx = flagpos.x
        fy = flagpos.y
        self.buildXY("fire-trap", fx, fy)
        self.pickUpFlag(flag)

#13

Oh NOW I GET IT I completely forgot there were flags in the first place thanks man :smile:
I just completed it man Nick thanks a lot there are barely any ppl that actually took there time to help me and thank you for being a great coder :smiley:


#14

No problem. Now that you mention it, maybe I should be putting this stuff in the guide for each level (and then showing players where the guide is).


#15

thanks that took FOREVER this really helped alot. hopefuly i can get my wizard now


#16

Hi Nick, I encountered an issue with this level, it is not related to code, but the flag option does not appear, thus I’m unable to drop flag. I checked and is sure that I’ve equipped flag, but just can’t see the flag (Green/Yellow/Violet) option. Can you help to check? Thanks!


#17

Did you hit submit? I think you don’t get the flags until you do, then they should be in the bottom left corner.


#18

Still doesn’t work. I sat at the computer for three hours on that one level and still it didn’t work. Please can you show me what the code is? This game is becoming more of a massive waste of time than fun. I tried what you wrote but it says that everything is incorrect: the if shouldn’t be there, the else shouldn’t, fy and fx don’t exist as a command, and the occasional random indent that causes chaos in the code. I’ve tried everything! Please send me the code in a private message or something or you may lose a subscriber!


#19

Hey Owen, sent you a private message with the solution–let me know what confused you so we can sort it out. Hope this helps!


#20

Thank you so much! I finally beated this level.