Difference between revisions of "Common development problems"
Line 2: | Line 2: | ||
This is a list of some of the most common problems people come across while playing the game. |
This is a list of some of the most common problems people come across while playing the game. |
||
− | =Creep.build silently fails= |
+ | ==Creep.build silently fails== |
There is probably a creep standing on the construction site. This is intended behavior; however, the fact that there is no error code for this is a known bug. |
There is probably a creep standing on the construction site. This is intended behavior; however, the fact that there is no error code for this is a known bug. |
||
Revision as of 04:49, 10 January 2021
This article is a stub. You can help Screeps Wiki by editing to add more information. This is a list of some of the most common problems people come across while playing the game.
Creep.build silently fails
There is probably a creep standing on the construction site. This is intended behavior; however, the fact that there is no error code for this is a known bug.
Why are all my creeps one role?
If you have made some new changes to you code and you suddenly find that all your creeps are the same role, likely when assigning, searching or checking the new role somewhere a =
is suppose to be a ==
for example if your running logic for a creep if(creep.memory.role = 'roleName')
Will set every creep run, to the role name, instead of comparing.
How can I tell what my creep/tombstone/container is storing?
You can use Object.keys()
on the object's store
property to retrieve the keys that are active, then check the amounts by looping though the keys and its store.
Why is store.getXXX() returning Null?
If you do not provide a RESOURCE_*
(Where * is a resource) constant to the method, and it is a non-generalized store it will return null. A generalized store (Terminal, storage) will return the 'total' regardless, but most other objects will not.
What is using all my CPU!?
You can use https://docs.screeps.com/api/#Game.cpu.getUsed before and after various parts of your code to determine how much CPU a certain snippet uses.
Why is pathfinder pathing though my spawn/extension/tower?
By default, pathfinder only uses terrain. You need to provide a roomCallback
with a costMatrix
with the buildings/objects you wish to avoid set.
Why is my pathfinder path not working with moveByPath and/or not what I want?
There are a few common issues that can happen when using pathfinder if not set correctly.
- If your object is on a terrain wall (Source/Controller/ect) or otherwise 'not possible' for a creep to stand on, you need to provide a range for the goal object. Elsewise, it will not be able to find the object as an 'end goal' as walls are not path able by default. (see API doc)
- If you are passing the whole return from to moveByPath, then it will not recognize it as a path. You need to use the
path
property of the returned object, which is the 'path' - If the path is not what you thought it 'should' be, check the
incompelete
property of the returned object, if true, then the path could not be found. It is possible for some reasons mentioned here for that to occur, or it simply ran out ofops
before it could find the path. themaxOps
by default is 2000, however you can set this higher if need be. - If you are storing the path in
Memory
to use later on, you will probably find that moveByPath will return an error. This is because when an object is stored to memory, it isJSON.stringified()
into a string, saved, then next tick on first memory callJSON.parsed()
into an object again. However, this object is now 'new' and is not aroomPosition
even though it still contains, x,y, and roomName.moveByPath()
accepts an array ofroomPositions
not of this new object, as such you need to reconstrue each obj in the array back to a roomPosition, or use another method to encode it.
Why can't I dismantle this InvaderCore!?
Invader cores are alien, Invader technology, as such careful and effective dismantling by a creep is ineffectual. However, it is still quite possible to bluntly attack and destroy it.
(code reason: It doesn't have an entry in the CONSTRUCTION_COST
constant, as such calling dismantle()
will return before any damage is done)
Why is getObjectByID() not returning an Object?
If your object is in a room you do not have vision on, then you will not be able to fetch the object.
Why is my game object in memory not working/updating?
Storing a live-game object in memory makes it 'stale', and not reference the original. This is because when an object is stored to Memory
it is JSON.stringified()
for storage, and next tick on first Memory
call, JSON.parsed()
into a new object, losing all reference to its live counterpart. It is recommended you instead store its ID
so you can retrive it when necessary using Game.getObjectByID()
Why is my creep not using exclusively roads with moveTo?
While roads are 'preferred' when set with the cost-matrix for the default moveTo, they are not 'only' considered. It is quite possible for steps off the road to be taken, you may want to consider using path-caching or other methods such as a custom costMatrix to make them take the path you desire.
Why is creep.transfer() returning an error when targeting my controller?
Likely, your creep does not have any WORK
parts, the proper method in upgrading a controller is upgradeController
which is called by default when using transfer()
and the target is a controller. See the: https://docs.screeps.com/api/#Creep.upgradeController API doc.
Why is my spawn not generating any more energy, shouldn't it generate to 300?
A spawn will only generate energy when the total room energy is <300, check extensions (even if not owned by you) to see if there is energy there.
Why does findClosestByRange & Path not working?
If your object is outside the room, is a common issue. findClosest only works for in-room objects, you have to code your own solution for out-of-room objects. findClosestByPath can also fail to 'find' or detect an object if a path can not be found/fails to be found.