Help with siege-of-stonehold


#1

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);
}
}

#2

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


#3

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);
}
}


#4

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.)


#5

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


#6

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.


#7

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.


#8

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


#9

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


#10

https://earthsunmoon


#11

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


#12

@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!