javascript - screeps - can't make variable in source -
i new screeps (love it) , having hard time create variable sources in room. trying make sure 3 creeps work on same source, have following code-snippet harvester , main module
main
var sources = game.spawns.spawn1.room.find(find_sources); (var in sources) { var source = (sources[a]); source.memory.numpeopleat = 0; } module.exports.loop = function () { ... }
harvester
var sources = creep.room.find(find_sources); (var s in sources) { if (creep.harvest(sources[s]) == err_not_in_range && sources[s].memory.numpeopleat < 3) { creep.moveto(sources[s]); sources[s].memory.numpeopleat++; break; } }
i know still have make function sources[s].memory.numpeopleatt--
thanks in advance,
jari van melckebeke
source doesn't have memory property creep does. however, can add main memory object.
var sources = game.spawns.spawn1.room.find(find_sources); if (!memory.sources) { memory.sources = {}; } _.each(sources, function(source) { if (!memory.sources[source.id]) { memory.sources[source.id] = { numpeopleat: 0 }; } });
one thing note code run every game tick, need initialize if hasn't been initialized (that's if-checks for).
Comments
Post a Comment