Url to show room with selected object by it's id



  • Everybody uses in console output messages like "Creep builder23 doing something"

    Usually we provide url of the room like https://screeps.com/a/#!/room/W*N* in this messages to find out where it is.

    It will be cool to add object ID into url like this:
    https://screeps.com/a/#!/room/W10N10/<objectId>  
    When you open this link, you see room W10N10 with object <objectId> is already selected. So you don't waste time trying to find where is creep 'Alex' in this room, or which of 10 labs was mentioned in console message.  



  • I'd love having this as well.


  • Culture

    If you're using Chrome and the Screeps SC extension you can add your own little module to have this feature. 

    Example:

    In settings.json

    {
    "path": "modules/room.select.objectid.js",
    "runAt":{
    "onUpdate": "https://screeps.com/a/#!/room/"
    }
    }

    Create a new file modules/room.select.objectid.js

    /**
     * @summary Select object by id on room access.
     *
     * Example: https://screeps.com/a/#!/room/W10S10?objectid=57cd3a30c0551957424a1f47
     *
     */
    module.exports.init = function () {
        module.getScopeData("room", "Room", ['Room.objects'], function (Room) {
            var id = module.exports.getParameterByName("objectid");
            var objects = _.filter(Room.objects, { _id: id });

            if (objects.length) {
                Room.selectedObject = objects[0];
            } else {
                console.warn("Could not select object by id: " + id)
            }
        });
    }

    module.exports.update = function () {
        // not used.
    }

    // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
    module.exports.getParameterByName = function (name, url) {
        if (!url) {
            url = window.location.href;
        }
        name = name.replace(/[[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

     



  • would be nice to have that as a native feature. the mentioned workaround wont do it for the steamclient.



  • Guys check out the roomLink() function pinned in the #logging channel on the screeps slack. It will output a link to the console that, when clicked, will take you to the room where the object is and select it. EDIT: Note this works in the steam client as well as in chrome and does not require any extensions.