Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

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

 

Syntax

Code Block
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

Return values

ValueTypeNotesGame Version
<pos>Position object

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

The '.type' property was added to the object in Warzone 3.1 RC 3. On earlier versions, the 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

Example

Code Block
themeRDark
languagejavascript
titleBuild a factory, if we can...
linenumberstrue
// 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 and truck can reach location
  if (pos && droidCanReach(truck, pos.x, pos.y)) {
 
    // get droid to build factory at location
    orderDroidBuild(truck, DORDER_BUILD, struct, pos.x, pos.y);
 
  }
 
}
Div
classbox
Availability
Status
colourGreen
titleStable

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.

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

See also

Related articles: