So I ran the profiler and I find the result quite interesting. Most of the CPU usage is indeed pathfinding and creep.moveTo()
. Seems I will start working on caching paths in memory now. Thanks for the help!
Posts made by 4nytime
-
RE: How to determine CPU usage
-
RE: Bug Report: Creeps going to wrong room through creeps.moveTo
So basically you are saying that the path rout via the other room has cheaper movement cost? It kind of looks like the creep is unable to make a decision where to move. Ironically it just stops in the other room and doesn't move anymore, not finding any correct route. In the second case the swamp movement cost hast to be blocking the creep movement. I will try
maxRooms: 1
and see if it solves the problem. I also included the fix for the creep to go back to its target room when it enters an incorrect room. Maybe a pathfinding cost matrix could be of further help.. -
RE: Bug Report: Creeps going to wrong room through creeps.moveTo
Found some more cases in which this issue arises. Again I made a screenshot. This time the way was blocked by a swamp, so the creep just decided to go to the next room instead of crossing the swamp, lol. It's really tedious watching something like this happen so frequently.
-
How to determine CPU usage
I just recently started playing screeps and now I am running into the problem of CPU limit. I expanded to a second room and now the CPU sometimes hits over 30, even 40 per tick. Probably there are a lot more creeps to process being around ~30 Creeps in total. What I understand is that pathfinding and maybe also filtering use a lot of CPU. Probably that's quite high CPU cost filtering multiple times through all the creeps to determine which Creep lives in which room... and so on. Does anybody have a solution how to identify where a high CPU usage actually comes from, so I can improve the code.
-
RE: How to modify Objects in memory
It seems I found a solution. Now I am just directly accessing memory at a specific index. It's possible to simply write
memory.roomData[index] = some_data;
and it will create a new object index at that position. -
Bug Report: Creeps going to wrong room through creeps.moveTo
I was trying to introduce some remote harvesting as this issue occured: the creeps were going into a wrong room other than specified in the creep.moveTo function. I immediately thought this might have to do something with wrong indexing as the room is exactly one coordinate off the original target room.
Another possibility could be that the creeps pathfinding led it onto the exit field because the neighboring room has a very thin connection leading along the room exit.
- The creep was moving to a room different to what was given in the MoveTo function
- happened on shard 3 room W54 S48, neighbor room W54 S59
run: function(creep) { if (creep.room.name != creep.memory.home) { if (creep.pos.x == 0 || creep.pos.x == 49 || creep.pos.y == 0 || creep.pos.y == 49) { creep.moveTo(new RoomPosition(25, 25, creep.room.name)); } var distantSources = creep.room.find(FIND_SOURCES); if (distantSources.length > 0) { if(creep.harvest(distantSources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(distantSources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } else { creep.drop(RESOURCE_ENERGY, creep.store.getUsedCapacity(RESOURCE_ENERGY)); creep.say('⛏️'); } } } else { creep.moveTo(new RoomPosition(25, 25, creep.memory.roomId), {visualizePathStyle: {stroke: '#ffaa00'}}); } }
-
RE: How to modify Objects in memory
Thanks Xenofix for the reply. Yeah, as you can see I was working on a script form a scout unit that goes into neighboring rooms to store their room names and sources. So the initial problem was how to combine the existing stored data with the newly accquired data from a new room and I had some trouble figuring that out. Maybe that could use some reworking to only store source Ids as an array. Actually I wanted to store the room data as an array containing arrays (Array of Arrays) so I can access
roomData[index].sources[index].id
and so on. -
How to modify Objects in memory
I am trying to add data to an existing memory Object but can't get it to work. From what I know screeps stores objects in memory rather than arrays.However, also the normal object methods like .push() don't work for adding new entries to the object. Now I am trying to assign the existing memory to an object variable, maybe that will work. Does anyone know how this is supposed to be done? Code:
if (creep.room.memory.isVisited == false){ console.log("in new room"); var roomSources = creep.room.find(FIND_SOURCES); var roomData = {remoteRoom: creep.room.name, sources: roomSources}; var existingData = Object.assign(Game.rooms[creep.memory.home].memory.roomData); existingData.push(roomData); Game.rooms[creep.room.home].memory.roomData = existingData; }
-
Pathfinding is not completed
I am trying to place construction sites with roads to the exits of my room. Now the problem is that the path calculation stops right in the middle, leaving most of the operation undone. I guess this could be the function hitting CPU limits and the path is not fully completed. So what can I do to get complete paths? Maybe someone can explain how it's possible to execute more CPU demanding tasks at a time.
-
RE: Creep memory object inconsistent?
@orlet Yes, I am aware that there is a
.spawnCreep()
function. It is not yet updated in the tutorial, which is still using.createCreep()
-
RE: Creep memory object inconsistent?
@o4kapuk said in Creep memory object inconsistent?:
creep.memory.memory
?Make sure you never use
.createCreep()
(the third parameter of.createCreep()
is creep memory object, not an options object)I think now I understand. So if the creep memory is assigned through
.createCreep
, it cannot be changed later on? -
RE: Creep memory object inconsistent?
@o4kapuk I know what you mean. So far as a beginner I am only using one spawn in one room. Also
.spawnCreep()
gets called only once per tick if a certain condition is true.@donatzor said:
@4nytime That's weird, it looks like its calling creep.memory.memory...
exactly this^
My only explanation is, that
creep.memory.task
is another variable thencreep.memory.memory.task
, as this is a Json object, correct? Drawing the conclusion, setting a string value with = would mean to actually create a variable if it has no been established before, rather than accessing the custom memory.memory object that has been introduced at spawning. The "logical" problem only arises if a varibale has the same name as a member.. xD -
Pathfinding with collision detection, any tips?
I am using the room objects pathfinding function to navigate my creeps. Is there any way to figure out right away if any other creep might be blocking the way on any point along he path? The
room.findPath
function has a parameter that either avoids or ignores other creeps. Is there a callback or event?I am playing in a room where one of the sources is only accessible through a crack that is one single field in width only, which of course results in a massive jam of creeps if not beeing resolved correctly. Ideally, I want my creeps to intelligently avoid this source while beeing harvested by another creep and move to the second source, but which is further away. Maybe the creeps could wait in line until the way is cleared?
Any ideas, suggestions?
-
RE: Creep memory object inconsistent?
@donatzor Thanks for your reply. Here is the code that will later modify the memory entries:
if (Game.spawns['SP_001'].energy < Game.spawns['SP_001'].energyCapacity) { creep.memory.task = 'transport'; creep.memory.target = 'spawn'; creep.memory.path = creep.room.findPath(creep.pos, Game.spawns['SP_001'].pos); }
Somehow this particular code will not access the same Json memory object that was passed as a argument when the creep is spawned (see initial post). So my only explanation is that the spawnCreep function will add a whole json object named "memory" to the memory, whereas this code here will set two different strings named "task" and "target"... The strange thing is, that that's exactly the way it is displayed when I look into the memory:
Memory[5] Memory[2] task: harvest target: spawn task: upgrade target: controller path[8]
Basically there should only be only two strings. I don't know much of javascript, but maybe it is just a very unfortunate way of naming the Json object "memory" in the documentations example:
https://docs.screeps.com/api/#StructureSpawn.spawnCreep
Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'Worker1', { memory: {role: 'harvester'} });
-
Creep memory object inconsistent?
I am new to screeps and have trouble finding explanations on why the memory object on some spawned creeps seems inconistent. The memory gets assigned a task and target variable at creation:
spawn.spawnCreep( [WORK, WORK, CARRY, MOVE], 'newCreep', {memory: { target: 'source', task: 'harvest'}});
However, when the creep is selected to view its memory, the entry differes to an addition that is later mayde by another script, like changing the task for example:
if(creep.memory.target == 'spawn') { creep.memory.task = 'transport'; }
Why does the memory seem to differ? One memory object holds the initial JSON data and two other lines hold the current values, which means, it is entered twice. Is this the difference beween a creep 'memory' object and the global memory object, meaning, one entry stores a string whereas the other one is a JSON object? Please clarify, thank you