Siege of Stonehold (JS)

Why this piece of code does not work?

var flag = this.findFlag();
this.pickUpFlag(flag);

I used to just use this in the levels before to make the character move, but now it asks for a “flag object”

even if I hardcode the type of flag,such as

this.pickUpFlag(“green”);

it still not working.

You are probably trying to pickup a flag when one does not exist.

var flag = this.findFlag();
if (flag) {
    this.pickUpFlag(flag);
}

Sotonin is right.

You’ll want to:
-Get the flag’s position. (Do you remember how to extract the position of an item?)
-Move to the flag’s position.
-Then pick it up.

If you don’t move to a flag’s position, there is nothing to pick up at that X,Y coordinate.

Sotonin, You hint helped me pass the level, I’ve just forgot the if statement before picking up the flag.

but specify the position for the movement is unecessary.
In this level and the levels before the following was quite suficient to make the character follow the flags:

var flag = this.findFlag();
if (flag) {
this.pickUpFlag(flag);
}

Yup, we actually make the pickUpFlag go to the flag to pick it up to make things easier for you, same way we make attack move into range or buildXY move to where it can build.