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

Help with Siege of Stonehold (JavaScript)

var flagG = hero.findFlag("green");
var flagB = hero.findFlag("black");
var flag = hero.findFlag("green" || "black);
function pickUp(flag) {
    var item = hero.findNearestItem();
    var position = item.pos;
    var x = position.x;
    var y = position.y;
    var flagV = hero.findFlag(flagG);
    var flagB = hero.findFlag(FalgB);
    if (flagG) {
        hero.moveXY(x, y);
        hero.pickUpFlag(flagG);
    }
    if (flagB) {
        hero.moveXY(x, y);
        hero.pickUpFlag(flagB);
    }
}
var enemy = hero.findNearestEnemy();
while (true) {
    pickUp(flag);
    if (flagG)
        pickUp(flag);
    if (enemy) {
        hero.attack(enemy);
    }
    if (flagB) {
        pickUp(flag);
        var ready = hero.isReady("cleave");
        if (enemy) {
            if (ready) {
                hero.cleave(enemy);
            }
        }
    }
}

!
Can anyone explain why this happens? :arrow_down:
!

1 Like

The bad code isn’t in the line showing, but that line of code is where the error creates a problem. You didn’t close the quotations after black at the top. So when you call pickUp(flag), it can’t find the closing quotations which carries over into the next line of code. In fact, your posted code shows the error by making everything red.

var flag = hero.findFlag("green" || "black);