Strange reoccurring error
-
When deploying, running console commands, or making memory updates manually I occasionally get this error.
proto-room:13 this.job_list = new JobList(this); ^ TypeError: object is not a function at Room.jobList (proto-room:13:25) at Creep.job (proto-creep:106:22) at Creep.act (proto-creep:10:20) at arrayEach (/opt/engine/node_modules/lodash/index.js:1289:13) at Function.<anonymous> (/opt/engine/node_modules/lodash/index.js:3345:13) at main:14:7
This is the line it is referring to https://github.com/unstoppablecarl/screeps/blob/5da67634bb3aee7ec7eb7aecaaec77a5b52eac05/proto-room.js#L13
As you can see it is fine there should be no error.
-
This problem was already reported, but so solution so far or even a reaction from screeps ppl.
I have exact the same issue, I have a line in my code, which works perfectly. However, on console input or memory update, I get the following error:
// somewhere in the beginning of this file var reproductionManager = require("Creep_ReproductionManager"); // ... Actions_Creeps:35 reproductionManager.reproduce.call(creep); // <- implies, that the module was not imported ^ TypeError: Cannot read property 'call' of undefined
I can solve the error by simply adding
if (reproductionManager){ reproductionManager.reproduce.call(creep); }
this however makes no sense, because it is an imported module, which should exist anytime.
-
I never noticed this error occurring with files that are
require
'd in the module I'm calling a command from but only when calling them on objects I've modified the prototype of. It seems that any commands you run from the console will get executed BEFORE your scripts run, so before any prototype modifying code has run. You can check this yourself by making a function that eats a bunch of cycles away doing nothing(like finding a path over a 10 tile distance) and then place aconsole.log(Game.getUsedCpu());
on the first line of yourmain.js
.The docs make no mention of it, which in my opinion is should.
I solved this issue by making everything command based and just adding the command I wish to execute to the command queue.
When you're updating memory and you forget to put a ; at the end of your statement you'll get an error similar to this:
main:8
init();
^
TypeError: object is not a function
at main:8:1
it'll throw an error and forfeit your tick.
-
Also, don't be too hard pressed to receive an answer from the developer. They're pretty much doing this in their spare time on a shoestring I think.
One thing they could do to prevent the whole 'forfeit your tick' is by wrapping all console input in a try/catch block. In case an error occurs, display it and then run the regular script code.
-
One thing they could do to prevent the whole 'forfeit your tick' is by wrapping all console input in a try/catch block. In case an error occurs, display it and then run the regular script code.
I tried this and I still get the error.