Strange error when executing successful command from console.



  • Whenever I execute a command from the console, I get the following error:

    main:15
    builder(creep);
    ^
    TypeError: object is not a function
    at main:15:6

    Lines 14, 15, and 16 of my main module are as follows:

    if (creep.memory.role == 'builder') {
    builder(creep);
    }

    builder is a function that is in another module.

    The error seems to have nothing to do with the command being executed, and does not appear to interfere with it.



  • you would have to do require('moduleName').builder(Game.creeps["creepName"])



  • @QzarSTB:
    The actual error object is not a function is actually referring to builder, which is apparently not a function. The problem is that it is a function, and the error only occurs whenever I type a command into the console.



  • @DXsmiley, if you want to access a function from your console you'll have to require the module it's in as well. That's why you have to use the command you can see in my previous comment.



  • My guess is that the modules and the console is run on separate instances.
    As far as I can tell, the console is running on the global namespace while the main module (and the other modules you require('') from the main module) are running on another instance. Which means that whatever module (in this case builder) you load from the main module will not affect the console.



  • I have exactly the same problem: When executing an console command, I sporadically get an error in a piece of code which works completely fine otherwise!

    reproductionManager.reproduce.call(creep);
    TypeError: Cannot read property 'call' of undefined
    

    In regular script execution, this code works without problems! Just if I type a console command, I get this error now and then!

    I guess this has to do with a similar issue (which I already created a post about), that the regular code is not accessible from console anymore (Prototype declarations, enhancements of the global object, etc.)! :-((