Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Drop The Flag Level Help in Backwoods Forest

I STILL DON’T GET IT.THE CODE WON’T WORK FOR ME!!! I AM SO SAD.the program says that the code is invalid. please help!!!

2 Likes

Guys don’t forgget that u need to press submit to put a flag and make codes works , if you just put the codes and used run it won’t work cause you can’t put flags

2 Likes

What is your code @swody321? Did you hit submit so you can place flags.

2 Likes

Thank you matt, yes, it is the submit button issue. Solved now.

2 Likes

I got the drop flag question solved. But another issue with this level, the “findNearestItem” function seems not working. The original predefined codes consist of this item = findNearestItem() but this returns an error directly. And when moving your mouse to the definition of this function part, it returns undefined.

This will cause your hero not trying to find the nearest item and the level will timeout once you killed all the orges.

2 Likes

What glasses are you wearing? If you have upgraded your glasses you may need to change self.findNearestItem to what is provided on your new glasses.

2 Likes

Hi dwhittaker, thanks for the feedback, I checked and saw I use the wooden glasses. I tried to reload the game again and issues solved, now it works properly. Thanks!

1 Like

My problems and hours wasted was due to simple but stupid mistake. The spaces, i had to add double space after the if spaces because the statements are in a loop
loop:
if flag:
12345678 the space

don’t know if i explained it well, but i figured out with my own way to code for the x,y position of the flag but else wasn’t working because i made all the spaces equal to 4 before the statements. I hope this helps for those still in trouble :smile:
I will really remember everything now from this level after so much typing.

2 Likes

So this is my coed and yet I don’t know what’s wrong because when i place my flag my avatar just poops the trap right where he is and I don’t know what i’m missing so that he will move and plop the trap down where the x’s are. HELP ME PLEASE NICK!!!

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)

    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)
2 Likes

Sorry the code got messed up. For some reason when I posted the first part got lined up and the 2nd half got put in code.

2 Likes

put the three ` characters on their own lines above and below your code block.

2 Likes
flagpos = flag.pos
fx = pos.x
fy = pos.y
self.buildXY("fire-trap", fx, fy)
self.pickUpFlag(flag)

You’ll want to check over that code a bit more :slight_smile:

2 Likes

Oh yeah just saying you could make some code like this

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

to get the exact x and y of the flag

2 Likes

Actually that code will not work at all. You are redefining flag to flag.pos so it would need to be

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

to work.

however. all this variable reassignment is kind of pointless imo when this works just as well and is a one liner.

self.buildXY("fire-trap", flag.pos.x, flag.pos.y)

There’s really no need to redefine them as a new variable if you aren’t going to do something to modify them and want to preserve the original. In this case, nothing is being done to them, so why not pass them directly into the method :slight_smile:

3 Likes

mh I may have typed my code wrong
but the reason I do no use the one liner is because the fact that I do not have to write that long line over and over

2 Likes

Thats what copy and paste is for, if you need to do it over and over. Each way has it’s benefits. Slightly longer (not much though) single line vs 4 actual individual lines. I choose less not necessary code.

3 Likes

Brilliant! You’ve saved me a whole bunch of coding space, and typing time. I appreciate that!

Less unnecessary coding = more brain power for actually getting through the problems.

2 Likes

Hi,

I am trying to get through this level. I think I don’t have enough practice with the multiple items going together, such as build at the place you have placed your flag. I’m not sure what to do next. It seems like this one is a big jump from the previous level. Could anyone give some hints?

Here is my code:

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

loop {
var flag = this.findFlag();
if (flag) {
    // How do we get fx and fy from the flag's pos?
    var greenFlag = this.findFlag("green");
    if (greenFlag) {
        this.pickUpFlag(greenFlag);
    }
    
    this.buildXY("fire-trap", fx, fy);
    
    
    this.pickUpFlag(flag);
}
else {
    var item = this.findNearestItem();
    if (item) {
        var pos = item.pos;
        var itemX = pos.x;
        var itemY = pos.y;
        this.moveXY(itemX, itemY);
    }
}
}
2 Likes

So the sample code already looks for and picks up flags; you don’t need to add that part. You might want to reload to the original sample code. The important part are these two lines:

    // How do we get fx and fy from the flag's pos?
    this.buildXY("fire-trap", fx, fy);

What we’re trying to indicate here is that you should define fx and fy variables using the flag.pos property. There is an example of doing this for item.pos at the bottom. So you can add this right before the buildXY:

var flagPos = flag.pos;
var fx = flagPos.y;
var fy = flagPos.y;

Hope this helps.

2 Likes

By the way, @clare12345, as a subscriber, you can use the Contact button on the site to directly send us an email with links to your code that goes into our priority inbox, so we can automatically pull up your session and will see it sooner than if you post on the forum. Feel free to just mash that when you get stuck.

(If you’re not a subscriber, we can’t help you with specific level questions, only bugs, so keep using the forum and other players may be able to assist.)

3 Likes