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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -