How exactly does {filter:} work?
-
I'm a beginner, and in the tutorial, there is this part:
var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; }
and it's really confusing me. I don't get what format they want, what the => is for, and why it needs to return a value. If someone could break down the components that'd be greatly appreciated!
-
Nevermind, I figured it out. Apparently the "=>" is a way to define functions. This is the resource I used if you also want to learn.
-
Yes, though to expand on your question filter is an option for room.find that uses lodash's filter to search the result of the FIND_* you call, your passing it an object, filter, with the arguments you want it to use when searching.
When you pass it a filter, it calls the lodash here: https://github.com/screeps/engine/blob/master/src/game/rooms.js#L641
You can read more about lodash's filter here: https://lodash.com/docs/3.10.1#filter