dryRun option works when pasting directly in console but not when console.log()

  • Minimum information needed:

    Which shard is affected?

    Simulation room

    What happened?

    The following code

    console.log(Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], newName('harvester'), {dryRun : true})

    results in


    Pasting the following directly in the console creates the creep. Although the console just told me it was not possible.

    Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], 'harvester008', {dryRun : false})

    What should have happened?

    Yields 1 or true for the first line of code.

    How can we reproduce this?

    • Run Screeps in Simulation mode locally or on the Screeps simulation

    Optional information:

    The program should continue to console.log 0 after pasting the command manually but the console result is now -6 I cannot find a pattern in this behaviour. Also the following command

          {dryRun : true} == true)

    results in


  • Please see https://docs.screeps.com/api/#Constants and the documentation for StructureSpawn.spawnCreep.

    Screeps return codes are like return codes in C. 0 means success, and anything else is an error code that gives some explanation of what went wrong.

    So in your first example you specified dryRun: true and got 0 (OK) because it was possible. So you run with dryRun: false, and it creates the creep.

    Then you get -6 (ERR_NOT_ENOUGH_ENERGY), because you've just used the energy to spawn the first creep and you don't have enough to spawn another one.

    The final example gives -10 (ERR_INVALID_ARGS), because

    spawnCreep([WORK,CARRY,MOVE], 'bab', {dryRun: true} == true);

    is equivalant to:

    spawnCreep([WORK,CARRY,MOVE], 'bab', false);

    ...which is not valid.


  • @SystemParadox Thank you for pointing out the return codes. I was not familiar with those and apperantly I've overlooked those while reading the doc. As the opts dryRunis a BooleanI was somehow also expecting the result a Boolean. Also thank you for explaining the other error codes.