I have been struggling mightily today with the hero.command(…) method. I keep getting "argument error: Hero placeholder needs something to command.
Here’s my code for the simpler one, Ring Bearer. (I tried to separate the archers and soldiers into separate arrays for Hunter and Prey, so it’s even more confusing.)
What am I missing in terms of issuing commands?
function findSoldierOffset(soldiers, i) {
var soldier = soldiers[i];
var angle = i * 360 / soldiers.length;
return radialToCartesian(5, angle);
}
// This function does the math to determine the offset a soldier should stand at.
function radialToCartesian(radius, degrees) {
var radians = Math.PI / 180 * degrees;
var xOffset = radius * Math.cos(radians);
var yOffset = radius * Math.sin(radians);
return {x: xOffset, y: yOffset};
}
var peasant = hero.findByType("peasant")[0];
while(true) {
var soldiers = hero.findByType("soldier");
for (var i=0; i < soldiers.length; i++);
var soldier = soldiers[i];
var offset = findSoldierOffset(soldiers, i);
var XOffset = xOffset;
var YOffset = yOffset;
// Command the soldier to move to the new offset position.
hero.command(soldier, "move", {x: peasant.pos.x + XOffset, y: peasant.pos.y + YOffset});
// The hero should keep pace with the peasant!
hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
}