Binary Deployment Level - Kelvintaph Glacier

Right now this is the code I have:

var units = ['soldier', 'archer', 'griffin-rider'];

function decimalToBinary(decimal) {
    var binary = (decimal >>> 0).toString(2);
    return binary;
}

function decimalToTernary(decimal) {
    var ternary = (decimal >>> 0).toString(3);
    return ternary;
}

var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
    var friend = friends[i];
    if (friend.type == "paladin") {
        var decimal = 2;
    }
    if (friend.type == "warlock") {
        var decimal = 3;
    }
    if (decimal == 2) {
        var result = decimalToBinary(decimal)
    }
    if (decimal == 3) {
        var result = decimalToTernary(decimal)
    }
    for (var i = 0; i < result.length; i ++) {
        var unit = result[i];
        var built = hero.built[hero.built.length - 1];
        hero.summon(units[unit]);
        hero.command(built, "move", {'x': 12 + i * 6, 'y': friend.pos.y});
    }
}

I have been receiving an error in Line 39.

hero.command(built, "move", {'x': 12 + i * 6, 'y': friend.pos.y});

The error says that “Hero Placeholder needs something to command.”
I’m pretty sure that the “built” variable I created should function as identification for the most recent unit that I built. Is there something that I’m missing?

you need to define built after hero.summon() :slight_smile:

BTW, pretty good code! Only suggestion I have is that you use let and not var and just do return (decimal >>> 0).toString(base) instead of defining a new variable

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