spawn.createCreep() always returns -6, except from console?



  • given the following:

        SPAWN = Game.spawns['Spawn1'];
        WORKER = [WORK, WORK, CARRY, MOVE];

        spawning = {

            /** @param {String} role **/
            build: function(role){
                if(SPAWN.spawning) {
                    return;
                }
                console.log(SPAWN.createCreep(WORKER, null, {role: role}));
                }
        }

     

    From the console (or anywhere else in my code) `spawning.build('builder')` fails (outputting -6).  But in the console I can `SPAWN.createCreep(WORKER, null, {role: role})` and it works fine.  Any ideas?



  • D'oh!  Leaving this for posterity:

     

    There's a couple places where I did things like `var SPAWN = Game.spawns['Spawn1'];`.

    This only get's ran or updated infrequently (maybe when you push new code?).  NOT every tick.  

    So all my calls were going toward this "stale" version of the object.  

    Moved those things into an `init()` function, and it works!