Allow us to access .type of objects

  • When automating some of my logging I've stumbled into an odd problem - how to quickly determine what type of object is `this`. After quickly looking at some objects .toString I saw that they indeed call `this.type` but we cannot access that property (returns undefined).

    I am not sure what is the reason to not expose `this.type` for our scripts, but could we pretty please get access to it? It sure is easier than having to parse it out of strings, or running ifs to determine type of an object.

  • Have you tried typeof command?

  • Yep, with the same undefined result.


    Update, actually this is all you get when you use it right:


    So not much help!

  • (Game.getObjectById('57a025bdcfa3ffae361105ba')) instanceof StructureTower


  •     report(thing) {
            var report = "";
            report += "Report For "+  thing + "\n";
            if (thing.structureType != null) {
                report += "Type: STRUCTURE\n";
            } else if ( thing instanceof Creep ) {
                report += "Type: CREEP\n";
            report += "ID: " + + "\n";
            report += "---------------\n";
            report += "STRINGIFIED:\n" + JSON.stringify(thing) + "\n";
            report += "---------------\n";

    Report For [creep Kaelyn]
    Type: CREEP
    ID: 58841ace5f886cd81fe8c6a6

    Thanks your answers all helped me along!
    - Man from Future