(info) Other great resources: Official JS API docs, Scripting Forum

pickStructLocation()

Find a good location for a specific droid to build a specific structure.

 

Syntax

var pos = pickStructLocation(droid, structure, x, y);

Parameters

ParameterTypeMandatoryNotesGame Version
droidDroid object(tick)

The construction droid that will do the building.

Must be of type DROID_CONSTRUCT.

3.1 Beta 1
structureString(tick)The string ID of the type of structure you want to build.3.1 Beta 1
xNumber(tick)The x co-ordinate of the desired construction site.3.1 Beta 1
yNumber(tick)The y co-ordinate of the desired construction site.3.1 Beta 1

There is currently an undocumented "maxBlockingTiles" parameter that defines how many inaccessible tiles can be around a structure location in order to allow it to be built. It's not recommended to use the parameter as it will likely be changed in future.

Return values

ValueTypeNotesGame Version
<pos>Position object

A position object specifying the '.x' and '.y' co-ordinates where the structure can be built.

This also confirms that the construction droid can reach that location, so you don't need to do an additional droidCanReach() check.

Note: A '.type' property was added to the object in Warzone 3.1 RC 3 to make the <pos> object consistent with other Position objects. On earlier versions, the <pos> object did not have a '.type' property.

3.1 Beta 1

Updated in 3.1 RC 3

<error>ErrorInvalid parameters specified, for example the droid was not of type DROID_CONSTRUCT or the structure type was not found.3.1 Beta 1
undefinedUndefinedA suitable location can not be found within range of the co-ordinates requested (x and y parameters of the function).3.1 Beta 1

Notes

The function checks for suitable locations within a 60-tile area centred around the desired location, starting at the desired location and then moving outwards. If it can't find a suitable location within that area, it returns undefined.

The function checks to ensure that a wheeled construction droid can reach the location. This means that, for example, if you're trying to build on an island and your construction droid isn't already on that island, the function will not consider the island to be a suitable building place. So you probably want to get your droid close to the desired construction site before using pickStructLocation() in order to avoid disappointment.

Example

Build a factory, if we can...
// let's build a factory
var struct = "A0LightFactory";

// can we actually build a factory?
if (isStructureAvailable(struct)) {
 
  // this assumes we have a truck (will throw ReferenceError if not)
  // you should check other things (like truck not busy, etc) too
  // but we'll keep it super-basic for this example...
  var truck = enumDroid(me, DROID_CONSTRUCT)[0];
 
  // build it near our construction truck
  var pos = pickStructLocation(truck, struct, truck.x, truck.y);
 
  // check we found a location
  if (pos) {
 
    // get droid to build factory at location
    orderDroidBuild(truck, DORDER_BUILD, struct, pos.x, pos.y);
 
  }
 
}
Availability STABLE

Requires:

  • Warzone 3.1 Beta 1 and above
  • Return value changed in Warzone 3.1 RC 3

It's possible an additional parameter will be added in future versions to define the size of the gap required around the structure.

Contents

Jump to:

See also

Related articles: