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)
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)
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!
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)
Oh NOW I GET IT I completely forgot there were flags in the first place thanks man
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
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!
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!