RoomPosition in memory



  • Hey all,

    I am trying to do the following and don't understand why its not working the way I suppose it should:

    I have a creep with an information .memory.destination: RoomPosition

    Now if I'm trying to access this information in a function by console.log it gives me an array of two objects instead of the RoomPosition object.

    So for example:

    myFunction: function(myCreep, myRoomPosition) {
    console.log(myRoomPosition); // yields '[object Object]'
    var myRoomPosition2 = new RoomPosition(myRoomPosition.x,  myRoomPosition.y, myRoomPosition.roomName)
    console.log(myRoomPosition2) // yields the right thing '[room WxxNxx pos xx,yy]'
    ... }

    So what am I missing here? Why do I have to redeclare the RoomPosition object instead of just using it right from the creeps memory?

    Thanks a lot!



  • Okay,I just read
    http://docs.screeps.com/global-objects.html

    Got it now 😉

     


  • Culture

    When you store things in memory you're running it through "JSON.stringify" behind the scenes. JSON does not preserve full classes- it's objects are basically just dictionaries. The javascript json engine handles this by simply removing anything that can't be serialized, so you get the really dumb dictionaries as a result. When they are later parsed there is no class data associated with it, just the raw data, so it's on you to recreate the classes yourself.