Error from using array to findClosestByPath
-
Hi, i need a little help about my script to find the nearest ennemy including creeps and structures and excluding the controler :
var finds = [
FIND_HOSTILE_CREEPS,
FIND_HOSTILE_STRUCTURES,
FIND_HOSTILE_SPAWNS,
FIND_HOSTILE_CONSTRUCTION_SITES
];
var target = creep.pos.findClosestByPath( finds, { filter: ( o ) => { return ( o.structureType != STRUCTURE_CONTROLLER ); }});That give me this error : Error: Invalid room name ... anyone can help ?
-
From document, I don't think you can pass that array as findClosestByPath argument.
You should call
var hostiles = creep.pos.findClosestByPath(FIND_HOSTILE_CREEPS)
then
var structures = creep.pos.findClosestByPath(FIND_HOSTILE_STRUCTURES, { filter: (it) => it.structureType!=STRUCTURE_CONTROLLER })
-
I try this because of the doc : http://support.screeps.com/hc/en-us/articles/203079201-RoomPosition
var targets = [ Game.creeps.John, Game.creeps.Mike, room.getPositionAt(10,10) ]; var closest = creep.pos.findClosestByPath(targets);
-
Concatenating together a list of the different roomobjects could work fine. However, your array (finds) does not contain all the hostile creeps, hostile structures, etc. What it actually contains are the constants mapped to each of those find conditions. According to https://screeps.com/a/constants.js ,that would be:
FIND_HOSTILE_CREEPS: 103,
FIND_HOSTILE_STRUCTURES: 109,
FIND_HOSTILE_SPAWNS: 113,
FIND_HOSTILE_CONSTRUCTION_SITES: 115So you're not handing it an array of all the hostile targets in the room, you're handing it an array with the content: [103, 109, 113, 115]. Since findClosestByPath will accept either a constant (representing one of those find conditions) or an array of roomobjects, it tries to process it as an array of roomobjects and fails.