screeps-starter-python
1.0.0
1.0.0
  • Introduction
  • Logistics
    • Setup
    • Upgrading Transcrypt
  • Screeps API Usage
    • Constants
    • Optional Arguments
    • Objects - Basic Interaction
    • Objects - Creation and the Keyword "new"
  • Features
    • Console Commands
  • Lodash
    • Introduction
    • As Arguments to API Methods
  • Syntax Changes
    • Summary
    • in Opperator
    • List Behavior
    • del Operator
    • dict Iteration
Powered by GitBook
On this page

Was this helpful?

  1. Lodash

As Arguments to API Methods

In addition to accepting standard optional arguments that modify some specific aspect of an API call, methods that return an array of objects (most notably find*() methods) accept a Lodash filter as an optional argument. While the example syntax provided by the game will not work in your Python code, only minor changes are needed to produce a similar result.

Examples

Finding all extensions in a room:

extensions = creep.room.find(FIND_STRUCTURES, {
    "filter": lambda s: 
        s.structureType == STRUCTURE_ROAD
})

Finding the closest dropped resource that meets a multiple criteria:

dropped_energy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {
    "filter": lambda r: 
        r.resourceType == RESOURCE_ENERGY and r.amount >= 100
    })
PreviousIntroductionNextSummary

Last updated 4 years ago

Was this helpful?