Help with siege-of-stonehold

What is wrong with my code? It`s Javascript and my hero is just standing still when I place the flag.

loop {
var flagG = this.findFlag("green");
var flagV = this.findFlag("violet");
var flagB = this.findFlag("black");
if (flagG) {
    var posfG = flagG.pos;
    var posxG = posfG.x;
    var posyG = posfG.y;
    this.buildXY("fence", posxG, posyG);
}
else if (flagV) {
    var posfV = flagV.pos;
    var posxV = posfV.x;
    var posyV = posfV.y;
    this.buildXY("fire-trap", posxV, posyV);
}
else if (flagB) {
    var posfB = flagB.pos;
    var posxB = posfB.x;
    var posyB = posfB.y;
    this.moveXY(posxB, posyB);
}
}

When you reach the destination marked by a flag, you have to remove it with the function this.pickupFlag()

I had a go at this command, but my hero is still standing like he`s never gonna move and the message ā€œUnreachable while after returnā€ keeps on appearingā€¦

loop {
var flagG = this.findFlag(ā€œgreenā€);
var flagV = this.findFlag(ā€œvioletā€);
var flagB = this.findFlag(ā€œblackā€);
if (flagG) {
var posfG = flagG.pos;
var posxG = posfG.x;
var posyG = posfG.y;
this.buildXY(ā€œfenceā€, posxG, posyG);
this.pickUpFlag(ā€œgreenā€);
}
else if (flagV) {
var posfV = flagV.pos;
var posxV = posfV.x;
var posyV = posfV.y;
this.buildXY(ā€œfire-trapā€, posxV, posyV);
this.pickUpFlag(violet);
}
else if (flagB) {
var posfB = flagB.pos;
var posxB = posfB.x;
var posyB = posfB.y;
this.moveXY(posxB, posyB);
this.pickUpFlag(black);
}
}

Function: this.pickupFlag (<object flag>) removes a ā€œflagā€. Its parameter must be an object of type ā€œflagā€:

var flag = this.findFlag(); // Variable type "flag"
if (flag) {
    this.pickUpFlag(flag);
}

That is, it can not be a string:

 this.pickUpFlag ("green");

Or a variable that you have not declared:

 this.pickUpFlag (violet); // You have not declared any variable "violet"

In addition, this.pickUpFlag lets you move to the position of the flag, so you do not need to make a this.moveXY ()

And remember that first you have to pick up the flag (pickUpFlag) and then perform other actions you want (moveXY, buildXY, etc.)

2 Likes

if (flagG) {

that the problem , you started the loop with a green variable wich is not existed yet , make a variables called it as flag = find flag then use your codes insdie another if flag statment , hit submit a post a flag somewhere , hope itā€™s help you

No thats not his problem. its defined at the top of the loop.

var flagG = this.findFlag("green");

Basically. yes no flag will be down yet and it will stand there until you drop a flag of some color as expected.

i think @juan did a great job explaining all his errors.

That sounds like maybe there is more to your code than you are posting. Is there something more before your loop?

Also, I think they are right that
this.pickUpFlag("green")
will not work, it might though. Better is:
this.pickUpFlag(flagG)

Your code looks like it should work other than that though, you will just stand there until a flag is placed though.

IF UNREACHABLE ā€˜WHILEā€™ AFTER 'RETURN ā€™ APPEARS, JUST DELEAT THE RETURN AT THE TOP OKAY:
return;
!loop { /*Unreachable while after return */}

https://code.combat.com/play/level/siege-of-stonehold

https://earthsunmoon

Go to the other thread https://what-are-you-supposed-to-do-in-siege-of-stone-hold

@shoodong Please donā€™t post so many unrelated messages in a thread in a row. If you have more ideas, you can edit your one existing post in a thread. Try also to not resurrect old threads that no one is paying attention to any more, especially if there are newer threads on the same topic.

Thanks!

1 Like