TypeError in PathFinder: a.getRangeTo is not a function
-
TypeError: a.getRangeTo is not a function
at h:5:6733
at Object.c.search:5:11195
at Object.e.PathFinder.search:7:9249
at Object.helperMethods.findSource:39:41
at Object.roleHarvester.run:9:31
at Object.module.exports.loop:22:40
at __mainLoop:1:14194
at eval:2:4
-
i'd dare say a is not the object you think it is (try console.log to confirm). would need more code to know whats actually going on
-
var sources = creep.room.find(FIND_SOURCES);
var target = creep.room.find(FIND_MY_SPAWNS)[0];
var nearestSource = {source: sources[0], pathLength: 100000};
for(var i = 0; i < sources.length; i++) {
var source = sources[i];
var pathLength = creep.room.findPath(target.pos, source.pos).length;
//var pathLength = PathFinder.search({pos: target.pos, range: 1}, {pos: source.pos, range: 1}).path;
if (pathLength < nearestSource.pathLength)
nearestSource = {source: source, pathLength: pathLength};
}The outcommented code is the code that didn't work and produced the above error.
Thanks for your help!
-
sorry haven't played with Path code yet but here's something that could help:
var Exit = creep.pos.findClosestByPath(exitDir);
or
targets.sort(function(a, b) {return creep.pos.getRangeTo(a) - creep.pos.getRangeTo(b)});
I believe theres a findClosestByRange as well, but generally you shouldnt need to do the for loop like that
-
Try providing current position as target.pos instead of { pos: target.pos, range: 1 }. I might be wrong but according to docs it seems only destination accepts object like that. Primary position is simple position object.