[SOLVED]Binary Deployment Error

What is wrong here please help:

// Recruit soldiers and archers to fill out each squadron.
// Each paladin has a decimal number stored in her deployment attribute.
// Convert these to binary and represent them with lines of soldiers and archers next to each paladin.
// Soldiers are 0s, archers are 1s.
// For the bonus goal, add griffins as 2s for trinary number lines next to the warlocks.
// Check the guide for help with binary numbers.
var paladins = hero.findByType("paladin");
for (var i = 0; i < paladins.length; i++) {
    var paladin = paladins[i];
    var n = paladin.deployment;
    var devider = 2;
    var result = [];
    while (n > 0) {
        if (n % devider !== 0) {
            result.push(1);
            n -= devider / 2;
        } else {
            result.push(0);
        }
        devider *= 2;
    }
    if (result.length < 8) {
        for (var j = result.length; j < 8; j++) {
            result.push(0);
        }
    }
    result = result.reverse();
    var posX = paladin.pos.x;
    var posY = paladin.pos.y;
    var built;
    for (var bruhSoManyVars = 0; bruhSoManyVars < result.length; bruhSoManyVars++) {
        var resultValue = result[bruhSoManyVars];
        if (resultValue === 0) {
            hero.summon("soldier");
            built = hero.built;
            hero.command(built[built.length], "move", {
                "x": posX + bruhSoManyVars * 8,
                "y": posY
            });
        } else {
            hero.summon("archer");
            built = hero.built;
            hero.command(built[hero.built.length], "move", {
                "x": posX + bruhSoManyVars * 8,
                "y": posY
            });
        }
    }
}

Don’t mind my messy, uncompact code and stupid varible names please I’m only 10 don’t judge me

I’m not exactly familiar with this level but I’m pretty sure the posY that is included in the error should be PosY and then whatever position it is just like the posX

Again I’m not exactly sure I do know that @Deadpool198 could help if my help isn’t working…

:wolf::wolf::wolf:
-@Luke10

nope didn’t work. it told me to try hero.pos instead but that was not what i wanted

Hi Greninja714,

Well done on the code - you’re right it’s a bit complicated to read, but if it makes sense to you then you’re really close!

I think the error message is from this line:

hero.command(built[built.length]

Have a think about an array. If the hero has built 8 units, then they will be in an array as [unit 0, unit 1, unit 2…unit 7]. At the moment you’re calling unit 8…

I think you’ll have a bit more work more work on the x variable that you’re sending the soldiers and archers to (but it might just be that you’ve written the code differently to me).

You’re doing really well, keep going on this one!

Jenny

1 Like

Thanks, it worked! Sort of. I changed it to hero.command(built[built.length - 1]); but now this happens:


And even though everything looks alright, it just keeps saying ran out of time.

1 Like

The solution was close enough though, thank you.

1 Like

so is it solved???

1 Like

no, but i think we can end it here
i’ll figure out the rest

1 Like

good luck @Greninja714

1 Like

did it! 20 characters

3 Likes

Congrats(20 charrrrr)

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.