findClosestByPath returns an object, but can't find the path
-
As the title suggests, a creep can find the object closest by path, but can't find the path to the object?
Context is a creep just entering a new room, and looking for a source to harvest. I refactored the code to find the error, so don't think about the specifics too much.
Relevant code:
I don't understand how creep.pos.findClosestByPath can return an instance of an object, but creep.moveTo(object) can't find a path.
The relevant room; creep position drawn in red
-
You have to specify the creep to move to
creep.moveTo(source[0])
instead of justcreep.moveTo(source)
.
-
Looks like Marvin was helping you out on the discord, so assume that's the same challange you were having.
@Tobyers
findClosestByPath
returns one object from a find constant search or an array of objects, whatever object is closest by all resulting paths searched to all objects. Your likely thinking ofroom.find()
which returns an array, which then you have to pick one object from it.
-
Yeah, I don't really know what I was thinking it was