findClosest only work now and then
-
I have a list of extensions and try to get the closest extension. For that I use the following code:
'''
if (extensions.length) {
console.log(creep.name + ' found '+ extensions + ' extensions.')
energyDropOff = creep.pos.findClosest(extensions);
console.log(creep.name + ' goes to ' + energyDropOff);
}
'''Sometimes I get the following log:
[11:04:08PM]Victoria found [spawn Spawn4],[structure (extension) #55a3e402368e5ead526b74f0],[structure (extension) #55a3e7c3d7b98859762c0f50],[structure (extension) #55a3eb86358f887c0c8a579a],[structure (extension) #55a4003c358f887c0c8a62d9],[structure (extension) #55a3f567e45ec680778026d4],[structure (extension) #55a3fa8b5f6db8b052603ca7] extensions.
[11:04:08 PM]Victoria goes to [structure (extension) #55a4003c358f887c0c8a62d9]Sometimes I get this:
[11:05:43 PM]Victoria found [spawn Spawn4],[structure (extension) #55a3e402368e5ead526b74f0],[structure (extension) #55a3e7c3d7b98859762c0f50],[structure (extension) #55a3eb86358f887c0c8a579a],[structure (extension) #55a4003c358f887c0c8a62d9],[structure (extension) #55a3f567e45ec680778026d4],[structure (extension) #55a3fa8b5f6db8b052603ca7] extensions.
[11:05:43 PM]Victoria goes to nullAnnoying thing is that most of the time it is the last result so my creeps are moving very slowly.
-
And I do need to work on my 'Markdown' skills
-
One key note about findClosest is that it's trying to find a path to object ( and therefore is very slow) as opposite to findClosestByRange which just gives you distance.
If the path is blocked by another creep - the function will return null.
-
There are 2 creeps in that room walking around and it happens even if they are opposite of the location where the extensions are.
However, thanks for thinking with me Dark.
-
Dark, your idea got me thinking. Been fiddling around with the options on findClosest and putting the algorithm: 'astar' in it solved the issue.
Thanks again.
-
Thanks for reporting, this must be fixed now.