Solved / CostMatrix, costCallBack, does not work.



  •  

    This is my code, there is no error. But it does not work, Could you help me ?
    [code]
    var path = creep.room.findPath(
    new RoomPosition(creep.pos.x,creep.pos.y,creep.pos.roomName),
    target[creep.pos.roomName],{
    costCallback : function(roomName, costMatrix){
    var hostiles = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 5);
    var swamps = creep.room.lookForAtArea(LOOK_TERRAIN,0,0,49,49,true);
    creep.room.visual.rect(creep.pos.x - 1, creep.pos.y - 1,2, 2, {fill: 'transparent', stroke: '#f00'});
    for(var swamp in swamps){
    var lookObject =swamps[swamp];
    if(lookObject.terrain == 'swamp'){
    costMatrix.set(lookObject.x,lookObject.y, 0);
    new RoomVisual(roomName).circle(lookObject.x,lookObject.y,{fill:"#ffffff"});
    }
    };

    for(var hostile in hostiles){
    for(var i=0;i<7;i++){
    var x = hostiles[hostile];
    x.pos.x = (x.pos.x-3+i);
    x.pos.y -= 3;
    costMatrix.set(x.pos.x,x.pos.y, 999);
    new RoomVisual(roomName).circle(x.pos.x,x.pos.y,{fill:"#1ba8e0"});
    }

    for(var i=0;i<7;i++){
    var x = hostiles[hostile];
    x.pos.x = (x.pos.x-3+i);
    x.pos.y += 3;
    costMatrix.set(x.pos.x,x.pos.y, 999);
    new RoomVisual(roomName).circle(x.pos.x,x.pos.y,{fill:"#1ba8e0"});
    }

    for(var i=0;i<4;i++){
    var x = hostiles[hostile];
    x.pos.x -= 3;
    x.pos.y = (x.pos.y3-2+i);
    costMatrix.set(x.pos.x,x.pos.y, 999);
    new RoomVisual(roomName).circle(x.pos.x,x.pos.y,{fill:"#1ba8e0"});
    }

    for(var i=0;i<4;i++){
    var x = hostiles[hostile];
    x.pos.x += 3;
    x.pos.y = (x.pos.y3-2+i);
    costMatrix.set(x.pos.x,x.pos.y, 999);
    new RoomVisual(roomName).circle(x.pos.x,x.pos.y,{fill:"#1ba8e0"});
    }
    }
    }
    }
    );[/code]



  • I set the positions wrongly, I edit it it works. Sorry.