user3649110
user3649110

Reputation: 79

Screeps getDirectionTo returning -2

var enemy_creep = creep.pos.findNearest(Game.HOSTILE_CREEPS);

if (enemy_creep) 
    var enemy_direction = creep.pos.getDirectionTo(enemy_creep);

I'm trying to do something like this in screeps but this function just keeps returning -2. I don't see any mention in the documentation of this error code. I've also tried the other version of the function using the x and y position of the enemy creep with the same result.

Upvotes: 0

Views: 284

Answers (2)

Anima-t3d
Anima-t3d

Reputation: 3565

I think -2 is the error code for no path found, based on the game constants (below notify) So what ch4rlyp is saying might be correct, although the game docs are not saying anything about it needing to be near. Perhaps it's a bug?

Game.ERR_NO_PATH -2

Upvotes: 1

ch4rlyp
ch4rlyp

Reputation: 11

We can know the direction of a enemy but only if it's near your own creep, works fine with findInRange(Game.HOSTILE_CREEPS, 1).

var enemy_creep = creep.pos.findInRange(Game.HOSTILE_CREEPS, 1)[0];

if (enemy_creep) {
    var enemy_direction = creep.pos.getDirectionTo(enemy_creep);
}

Upvotes: 1

Related Questions