Add MODE_PTR to the modes list inside a room


  • Culture

    I thought it would be handy to determine that you're running in PTR space.

    Can we add MODE_PTR to the room.mode ?

     

    http://support.screeps.com/hc/en-us/articles/203079011-Room#mode

     

    Regards,

    Dissi


  • Dev Team

    It doesn't make any sense to make runtime checks for PTR, since it is always a whole another account and codebase. If you use grunt task, you can determine where you are deploying to beforehand, and fork your code state knowing that.

    For example, create a simple file named ptr.js:

    module.exports = true;

    And use it in your Gruntfile.js:

    module.exports = function(grunt) {
    grunt.loadNpmTasks('grunt-screeps');
    grunt.initConfig({
    screeps: {
    options: {
    email: 'YOUR_EMAIL',
    password: 'YOUR_PASSWORD',
    branch: 'default',
    ptr: require('dist/ptr') // <--
    },
    dist: {
    src: ['dist/*.js']
    }
    }
    });
    And in your game script:
    var isPtr = require('ptr');
    module.exports.loop = function() {
      ...
    }
    This way you can always know which server your script is being run at.

  • Culture

    I never knew grunt worked like that as well, that's quite handy! Thanks for the quick information



  • Not everyone uses `grunt`

    And since you understand it so completely... could you use your own advice and thus solve the problem for everyone no matter how they choose to run their code.

    MODE_SIMULATION: "simulation", 
    MODE_SURVIVAL: "survival",
    MODE_WORLD: "world",
    MODE_ARENA: "arena",
    Add:
    MODE_PTR: "PTR",
    **NOTE** there is an error in the return for the code (it returns "world" in PTR and WORLD):
    Game.rooms['W##S##'].mode

    Cool use for grunt though ... I have ideas to use your example for something else.


  • Culture

    I don't think this should be a different mode. The `modes` are the same between PTR and the real world- they are both worlds.

    Instead I think we need to start getting "shard" or "server" ids. This way it would be easier to see if your code is running on a specific private server, the main public server, ptr, or in the future once we have shards it can distinguish between shards.

    While it is possible to emulate this using memory, it is not possible to distinguish between PTR and the World that way.