9

Fascinating game!

Looking for an example of how to persist a reference to a particular energy source in a creep's memory. Seems that storing the actual source object won't work(?).

bitbutter
  • 580
  • 5
  • 15

1 Answers1

14

You can't store object instances, but you can store their IDs.

if(!creep.memory.targetSourceId) {
    var source = creep.pos.findNearest(Game.SOURCES_ACTIVE);
    creep.memory.targetSourceId = source.id;
}  

And then you can use Game.getObjectById() to find this particular source.

var source = Game.getObjectById(creep.memory.targetSourceId);
creep.moveTo(source);
artch
  • 4,487
  • 2
  • 28
  • 35