The actual problem was that I use a list of "sources" dependent to the creep role, and long story short, when the storage was missing (like in a new room) the correspondant "source" element wasn't null, but an array with null as element, so the find function was trying to find the pos property of that null element.
Frhay
@Frhay
Posts made by Frhay
-
RE: [Solved] Property pos empty on creep in remote room
-
RE: [Solved] Property pos empty on creep in remote room
Ok, my bad, turns out you were right Spite, the sources variable was actually empty and the script was dying inside the finder function.
I really didn't realize my new caching system was failing so hard for new rooms, good to know.
Many thanks to you my friend. May your storage be always full of useful stuff!
-
RE: [Solved] Property pos empty on creep in remote room
Well the exception error message is "Cannot read property 'pos' of undefined" meaning that undefined is the element on which I'm calling the pos property.
But your point could be valid, if the js stack trace is not accurate enough, and by experience I know they are sometimes not really accurate actually.
That said I'll run a further investigation about it, checking if my "sources" variable is loaded or not (by the way it's a cache of FIND_SOURCES done by room).
Â
-
[Solved] Property pos empty on creep in remote room
Ok I used to have creeps in remote rooms but I don't remember if I already used the pos property on them while outside a controlled room.
I assumed that you have no access to Room objects when you have no structures or creeps in the room, but once you get a creep there you should have access to the correspondand Room object.
Now I have a creep in an uncontrolled room, and when I try to access its pos property I get an error stating that the creep itself is not defined.
Here's the snippet:
try {
var source = this.pos.findClosestByPath(sources);
} catch(err) {
console.log(err.message);
console.log(JSON.stringify(this));
this.say("Exception!");
return false;
}Note that "this" is a Creep object, since it's working in a prototype extension, and the rest of the code is treating "this" as a Creep correctly.
The console log prints:
Cannot read property 'pos' of undefined
{"room":{"name":"E38N57","mode":"world","energyAvailable":0,"energyCapacityAvailable":0},"pos":{"x":42,"y":20,"roomName":"E38N57"},"id":"57bf311759ad49491ec636ac","name":"Caden","body":[{"type":"work","hits":100},{"type":"carry","hits":100},{"type":"move","hits":100}],"my":true,"owner":{"username":"Frhay"},"spawning":false,"ticksToLive":1047,"carryCapacity":50,"carry":{"energy":0},"fatigue":0,"hits":300,"hitsMax":300,"saying":"Exception!"}So it means that it consider "this" as undefined, since it cannot access pos property, and at the same time it prints me the whole creep structure, meaning that it's actually a Creep object.
What am I missing?
Thanks in advantage for the useful answers!
-
RE: CPU Usage with require
Ouch, we wrote again at the same time!
Well I've just put a Game.cpu.getUsed() at the start of the main file, and one after the last require instruction.
All the required file are prototype extensions and module exportations, there's not further code executed before the main cycle (unless Skynet took over and I'm not aware!).
-
RE: CPU Usage with require
RaskVann we were writing at the same time.
Thanks for the link, I'll take a look at it. Also thanks for the useful informations.
-
RE: CPU Usage with require
It may be useful if I add some statistics IÂ got about my CPU usage in different stages of my scripts.
The standard usage is like this:
Used 2.3 for Modules /-/ Used 0.7 for Flags /-/ Used 3.9 for Creeps /-/ Used 0.7 for Rooms
With peaks going about this, doubling the CPU needed for modules inclusion:
Used 5.2 for Modules /-/ Used 0.8 for Flags /-/ Used 3.5 for Creeps /-/ Used 0.4 for Rooms
Then sometimes I get this:
Used 21.1 for Modules /-/ Used 0.9 for Flags /-/ Used 3.8 for Creeps /-/ Used 0.6 for Rooms
Now being my module files always the same, how can it take ten times to includ them sometimes? I know it's only a peak and the bucket can absorb it, but I'm also managing a single room with quite few different logics. I will of course need to extend a lot my code, thus increasing modules count and size. It can be hard to balance their weight being their inclusion cost so variable.
Tips? Suggestions?
-
CPU Usage with require
Hello my fellow Screepsers! (Screepsers?)
I know this topic has been already treated but I didn't find a single answer really going through some particulars about CPU usage and module inclusions.
It's stated that including modules has a cost in CPU, going against maximum available CPU for every tick.
It's also stated that every X ticks the game rebuilds modules so the cost in CPU for modules inclusion is higher.
It is not clear how much does modules weight and if this weight is influenced by the number of entities the modules are touching. For example if I have a module extending the Creep prototype, will the cost of its inclusion rise if I have more creeps? Or is it always the same and then the creeps actions will normally weight more the more I have?
And another question: would the code consume less CPU should I put all my functions, prototypes, everything, in the main file? Ok it woul be really messy, but should it remove CPU costs for including, it could be useful anyway, no?
Thanks again in advance for all the useful answers!
Â
-
RE: [Solved] Correct implementation of function library
I'm on holiday, so I forgot to login here too to say thanks for other answers!
Thanks for the hints about how to include my files with prototype extensions!
I converted most of my common functions into new functions extending Creep prototype and I must say I'm quite satisfied by the result, except for the CPU weight on module loading. But I'll open a new thread for that, since it's a separate topic.
Many thanks again to all of you who helped my out.
-
RE: [Solved] Correct implementation of function library
Now I feel stupid not having thought about that.
Many thanks my friend, may your creeps overrun your enemies and lay waste to their bases!