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

try using a builders hammer and while loop it: so that u always keep building the fire traps then when orgres come from the entrences then KABLOOM! if you ever need help u can use flags to command your hero to move to the healers spot and just let your soldiers do the dirty work, TIP: dont go attack thoktar

Wrong punctuation. ; instead of :. Change ; to :.[quote=“User1.1, post:1, topic:20005, full:true”]

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:
!
[/quote]

Or is ; the correct punctuation in javaScript?

Welcome to discourse @Oliver_Davidson