Difference between revisions of "Find Methods"

From Screeps Wiki
Jump to navigation Jump to search
(Created page with "Find methods, along with look methods are the primary way to get in-game objects. They are split up into two types. One type is using the find methods available in the Roo...")
 
Line 1: Line 1:
  +
{{stub}}
  +
 
Find methods, along with [[look methods]] are the primary way to get in-game objects. They are split up into two types. One type is using the find methods available in the Room object, and the other type is by using RoomPosition methods.
 
Find methods, along with [[look methods]] are the primary way to get in-game objects. They are split up into two types. One type is using the find methods available in the Room object, and the other type is by using RoomPosition methods.
   
Line 5: Line 7:
 
Find methods of the Room object will return an array of values or an integer error value, depending on the specific method. It is recommended to check the API prior to using them. Links to the method in the API are provided by clicking on the appropriate method below.
 
Find methods of the Room object will return an array of values or an integer error value, depending on the specific method. It is recommended to check the API prior to using them. Links to the method in the API are provided by clicking on the appropriate method below.
   
  +
=== [https://support.screeps.com/hc/en-us/articles/203079011-Room#find Room.find()] ===
=== room.find() ===
 
  +
 
Returns an array of objects that meet the specifications passed in the arguments. It can be passed a FIND_* constant, and has and optional filter argument.
  +
  +
=== [http://support.screeps.com/hc/en-us/articles/203079011-Room#findExitTo Room.findExitTo()] ===
  +
 
Returns an array of directional exit constants (e.g. FIND_EXIT_TOP) or an integer error value if there is no path or you pass an invalid argument. This is typically used in conjunction with another find method to get specific [[RoomPosition]]s matching the returned exit constants.
  +
 
=== Room.findPathTo() ===
   
  +
== Find methods in the RoomPosition object ==
[[https://support.screeps.com/hc/en-us/articles/203079011-Room#find |Room.find()]] find method will return an array of objects that meet the specifications passed in the arguments. It can be passed a FIND_* constant, and has and optional filter argument.
 
   
=== room.findExitTo() ===
+
=== RoomPosition.findClosestByRange() ===
  +
Finds the single closest object to the room position that meets the specifications and returns it. If there is no such object in the room, returns null.
   
  +
=== RoomPosition.findClosestByPath() ===
[[http://support.screeps.com/hc/en-us/articles/203079011-Room#findExitTo | room.findExitTo()]] will return an array of directional exit constants (e.g. FIND_EXIT_TOP) or an integer erro value if there is no path or you pass an invalid argument. This is typically used in conjunction with another find method to get specific [[RoomPosition]]s matching the returned exit constants.
 
  +
Works like <code>findClosestByRange()</code>, but measures distance by pathfinding, taking obstacles into account. This is better for finding, for example, the creep that can get to a certain position fastest, but it is more expensive [[CPU]]-wise.
   
=== room.findPathTo() ===
+
=== RoomPosition.findInRange() ===
  +
Finds all objects matching the specifications that are in a given range of the room position, returning them in an array.

Revision as of 04:05, 12 December 2016

This article is a stub. You can help Screeps Wiki by editing to add more information.

Find methods, along with look methods are the primary way to get in-game objects. They are split up into two types. One type is using the find methods available in the Room object, and the other type is by using RoomPosition methods.

Find methods in the Room object

Find methods of the Room object will return an array of values or an integer error value, depending on the specific method. It is recommended to check the API prior to using them. Links to the method in the API are provided by clicking on the appropriate method below.

Room.find()

Returns an array of objects that meet the specifications passed in the arguments. It can be passed a FIND_* constant, and has and optional filter argument.

Room.findExitTo()

Returns an array of directional exit constants (e.g. FIND_EXIT_TOP) or an integer error value if there is no path or you pass an invalid argument. This is typically used in conjunction with another find method to get specific RoomPositions matching the returned exit constants.

Room.findPathTo()

Find methods in the RoomPosition object

RoomPosition.findClosestByRange()

Finds the single closest object to the room position that meets the specifications and returns it. If there is no such object in the room, returns null.

RoomPosition.findClosestByPath()

Works like findClosestByRange(), but measures distance by pathfinding, taking obstacles into account. This is better for finding, for example, the creep that can get to a certain position fastest, but it is more expensive CPU-wise.

RoomPosition.findInRange()

Finds all objects matching the specifications that are in a given range of the room position, returning them in an array.