Other great resources: Official JS API docs, Scripting Forum

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

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

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 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);
 
  }
 
}
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:

 

  • No labels