Here’s my code so far:
var units = ['soldier', 'archer', 'griffin-rider'];
function decimalToBinary(decimal) {
let binary = (decimal % 2).toString();
while (decimal > 1) {
decimal = parseInt(decimal / 2);
binary = (decimal % 2) + (binary);
}
return binary;
}
function decimalToTernary(decimal) {
let ternary = (decimal % 3).toString();
while (decimal > 1) {
decimal = parseInt(decimal / 3);
ternary = (decimal % 3) + (ternary);
}
return ternary;
}
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
var integer = 0;
var result = null;
if (friend.type == "paladin") {
integer = 2;
}
if (friend.type == "warlock") {
ingeger = 3;
}
var decimal = friend.deployment;
if (integer == 2) {
result = decimalToBinary(decimal);
}
if (integer == 3) {
result = decimalToTernary(decimal);
}
for (var i = 0; i < result.length; i ++) {
var unit = result[i];
hero.summon(units[unit]);
var built = hero.built[hero.built.length - 1];
hero.command(built, "move", {'x': 16 + i * 8, 'y': friend.pos.y});
}
}
The binary and ternary functions are working as expected, but the for-loop ceases to work after the first deployment of troops, and only eight troops are sent to the field. It’s as if the index isn’t increasing as expected. I’m not sure what I did wrong. The system is not giving my errors, and the code looks as it should. Any help?