Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
(pseudo code)
You can itterate through them using FOR/IN or with a traditional numeric increment.
(pseudo code)
Or a numeric itteration through an array can be found in the screeps docs at: http://docs.screeps.com/api/#Game.market.deal
I only point out a regular numeric/index itteration because javascript is so loose that for/in can cause problems if you're not on the ball. Miscellaneous object literals drive me bananas...I just want regular multi-dimensional arrays.
Your filter only sorts the results for .hits not maxed. This is not a lowest-to-highest sort...it's just a list of not full HP results. Object.hits < Object.hitsMax is a numeric evaluation ( if 3 is less than 4, return true/object ) Web search for operators, or numeric operators. (Not trying to be condescending here, just trying to explain why your sort criteria isn't what you wanted )
Have a web search for the javascript function .sort. You can use it to bring your lowest hits object to the start of your results array, and then target[0]. Don't forget the loDash stuff is available throughout your screeps code too! https://lodash.com/docs/4.17.4
There's also a .sort sample at creep.repair() http://docs.screeps.com/api/#Creep.repair
I have one other question to add to this, which will be useful down the track though it's redundant with the info you've provided in this scenario. Is it possible to create a filter that excludes results that meet certain criteria? For example, if I were to create a filter for sorting a return list of creeps in a room based on their parts, but wanted to exclude creeps that have more or less than a certain number of parts... is that possible?
original Sample code:
You might add in:
I get the rooms via :
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => (structure.hits < (structure.hitsMax < 50000 ? structure.hitsMax : 50000))
});
if(closestDamagedStructure) {
if(closestDamagedStructure.hits < (closestDamagedStructure.hitsMax < 50000 ? closestDamagedStructure.hitsMax : 50000)) {
if(tower.energy > 500) {
tower.repair(closestDamagedStructure);
}
}
}
}
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
tower.attack(closestHostile);
}
}
}
}
};
module.exports = structureTower;[/code]