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

[SOLVED] Decoy Drill: JavaScript

Please help. So triggered, might stop dealing nut.
‘’’
while(true) {
var decoysBuilt = 0;
var coin = hero.findNearestItem();
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
if (hero.gold >= 25) {
hero.buildXY(“decoy”, hero.pos.x, hero.pos.y);
decoysBuilt += 1;

}

if (decoysBuilt == 4) {
    break;
}

}

hero.say(“Done building decoys!”);
hero.moveXY(14, 36);
hero.say(decoysBuilt);
‘’’

Hold Up, broke some forum rules. What I mean is:

while(true) {
    var decoysBuilt = 0;
    var coin = hero.findNearestItem();
    if(coin) {
       hero.moveXY(coin.pos.x, coin.pos.y);
    }
    if (hero.gold >= 25) {
        hero.buildXY("decoy", hero.pos.x, hero.pos.y);
        decoysBuilt += 1;
        
}
       
    if (decoysBuilt == 4) {
        break;
    }
}


hero.say("Done building decoys!");
hero.moveXY(14, 36);
hero.say(decoysBuilt);

For some reason, my variable isn’t increasing. Why?

i recommand this instead:
mod edit: removed.

Hi @mayro, welcome to the CodeCombat Discourse! :tada:

Look at where you’ve put this line:

It’s inside the loop…
Danny