-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Description
https://docs.screeps.com/contributed/modifying-prototypes.html
In set and get methods, "memory.sources" is different from "memory.sourceIds"
Object.defineProperty(Room.prototype, 'sources', {
get: function() {
// If we dont have the value stored locally
if (!this._sources) {
// If we dont have the value stored in memory
if (!this.memory.sourceIds) {
// Find the sources and store their id's in memory,
// NOT the full objects
this.memory.sourceIds = this.find(FIND_SOURCES)
.map(source => source.id);
}
// Get the source objects from the id's in memory and store them locally
this._sources = this.memory.sourceIds.map(id => Game.getObjectById(id));//this
}
// return the locally stored value
return this._sources;
},
set: function(newValue) {
// when storing in memory you will want to change the setter
// to set the memory value as well as the local value
this.memory.sources = newValue.map(source => source.id);//this
this._sources = newValue;
},
enumerable: false,
configurable: true
});Metadata
Metadata
Assignees
Labels
No labels