Creating a container and getting its id
-
I'm trying to build a container and retrieve the id of the construction site.
The constructing part works fine, i get an OK as result and see the site on the map.
However, retrieving it directly after the Construction Line fails with different kind of approaches.
With all the tests, i don't see the container. If I wait however one tick, it starts to appear. Why is that and is there any way to retrieve the id directly after creating it?testBuildContainer: function(room){
var result = room.createConstructionSite(10,10, STRUCTURE_CONTAINER);
console.log("result: " + result);
// Test 1
var room_find_c = room.find(FIND_CONSTRUCTION_SITES);
console.log(JSON.stringify(room_find_c, null, 4));
var room_find_s = room.find(FIND_STRUCTURES);
console.log(JSON.stringify(room_find_s, null, 4));
// Test 2
var room_lookat = room.lookAt(10,10);
console.log(JSON.stringify(room_lookat, null, 4));
// Test 3
console.log(JSON.stringify(room.find(FIND_CONSTRUCTION_SITES,{filter: (i)=> {return i.structureType==STRUCTURE_CONTAINER}}), null,4));
// Test 4
console.log(JSON.stringify(room.find(FIND_STRUCTURES,{filter: (i)=> {return i.structureType==STRUCTURE_CONTAINER}}), null,4));
}
-
Sadly this is not possible within the same tick.
The construction site will be available in the next tick. I suggest saving the roomposition to memory, so next tick you can grab it with a lookForAt()
-
Dissi is correct, but a greater thing to understand with this game is that every command you put into the server is *NOT* resolved immediately. Your code runs, generates some calls against the game server (along with all the other players), and then the game server resolves all of the different calls made by the different players. This means some interesting things:
1. move can return a 0 (success) but your creep may not move on the next tick (for various reasons, but most generally because another creep had a move call to move to the same location and the server chose that other one to "win")
2. any action to create things (spawning creeps, creating construction sites, creating flags, etc...) only happens on the next tick.
3. any action to destroy things (creep suicide, building destruction, flag destruction, construction site removal) only happens on the next tick.
4. related to this, creep actions that require resources (like repair, building, or transferring) require that the resource be contained in the creep (or structure, as this is also true of labs, towers, storages, etc..) before your code gets run (i.e. on the last tick). which means you can't say harvest energy and immediately use it to upgrade a controller on the same tick.