Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screeps: store reference to source in creeps memory?

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(?).

like image 541
bitbutter Avatar asked Nov 21 '14 12:11

bitbutter


1 Answers

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);
like image 60
artch Avatar answered Sep 29 '22 07:09

artch