I believe there seems to be a bug in the move command of the peasant. Please see below for a snippet illustrating the problem.
var peasants = base.getByType(‘peasant’);
for (var peasantIndex = 0; peasantIndex < peasants.length; peasantIndex++) {
var peasant = peasants[peasantIndex];
var xTarget = 0.0;
var yTarget = 0.0;
// I do my targetpos calculations here
base.say("x: " + xTarget + " y: " + yTarget); // This works, which means xTarget and yTarget are valid
base.command(peasant, ‘move’, new Vector(48, 48)); //This also works
base.command(peasant, ‘move’, new Vector(xTarget, yTarget)); // This gives an error saying:
// Cannot read property ‘x’ of null
}
I am filing it under bugs since I am reasonably certain there is nothing wrong with my code. Please re-categorize it if its something I am doing wrong and please point out my error.
@Hannofcart Checked out the code. I think that xTarget and yTarget are getting NaNs at some point right before the error occurs:
Could this be what’s doing it?
@Kirstin Seems like the reduce is expecting the starting value to be an object with {pos: new Vector(0, 0)} instead of just the straight-up new Vector(0, 0). I tried out making the adjustments to be operating on wrapper objects instead and then pulling out the answer as the pos property and it seemed to work.