findPathTo throwing error



  • The selected creep has this pos:

    {"x":31,"y":41,"roomName":"W6N1"}

    creep.memory.dest.pos (the energy source) is:

    {"x":31,"y":43,"roomName":"W6N1"}

    This command:

    creep.pos.findPathTo(creep.memory.dest.pos)

    Throws this error:

    Error: invalid arguments in RoomPosition constructor
    at new <anonymous> (evalmachine.<anonymous>:1:72)
    at .findPathTo (evalmachine.<anonymous>:1:72)
    at Object.run (role.harvester2:102:34)
    at Object.module.exports.loop (main:27:34)
    at __mainLoop:1:52

    What am I doing wrong?



  • I realize that putting objects in memory causes them to lose their type due to the JSON serialization. I feel "*-like" (as in "RoomPosition-like") objects shouldn't throw errors. In this case, I don't need a RoomPosition object to fulfill the practical requirements, I just need an object with an 'x' and 'y' attribute.

    Do we really need type checking in a language that is mostly type-agnostic? If an object doesn't have a property that's expected then throwing an error on the property access seems more appropriate (and easier to troubleshoot). Additionally, the type checking adds unnecessary overhead.

    Note: I was able to solve this with the obvious solution:

    creep.pos.findPathTo(creep.memory.dest.pos.x, creep.memory.dest.pos.y)



  • Imo pathing should work with structs similar to RoomPosition, as otherwise GC gets busy cleaning up all those RoomPosition objects.