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

getObject()

Three ways to retrieve a specific object...

 

Syntax

This function has 3 syntax options...
// Syntax #1: Retrieve object by label:
var obj = getObject(labelName);
 
// Syntax #2: Retrieve object by location (map tile):
var obj = getObject(x, y);
 
// Syntax #3: Retrieve object by player, id and type:
var obj = getObject(type, player, id);

Parameters

SyntaxParameterTypeMandatoryDescriptionGame version
#1labelNameString(tick)

Retrieve the object associated with the label name.

See Labels for more information.

3.2
#2x, yNumber(tick)

Specify the x,y co-ordinates of a map tile to return the Structure object or Feature object on that tile.

You cannot retrieve droid objects using this syntax, as there can be more than one droid on a tile. Instead, use enumArea() or enumRange().

3.2
#3typeConstant(tick)

The type of object to retrieve:

3.2
#3playerNumber(tick)

The player to which the object belongs.

When retrieving feature objects, specify player as -1.

3.2
#3idNumber(tick)

The object ID.

3.2

Return value

ValueTypeDescriptionGame version
<object>

Game object

Location object

The object that was retrieved.

You can determine what sort of object it is by inspecting its .type property.

3.2
undefinedUndefinedThe label was not found (applies to Syntax #1).3.2
nullNullNo object was found.3.2
<error>ErrorInvalid parameters specified.3.2

Notes

In earlier versions of Warzone, where getObject() is not available, there are some alternatives which you can use:

Syntax 1: LabelSyntax 2: LocationSyntax 3: Object IDs

3.2 early masters:

3.1 branch:

3.2 early masters:

3.1 branch – filter results from:

3.2 early masters:

3.1 Beta 2 → 3.1.0:

3.1 Beta 1:

Example

Syntax 1: Label
var obj = getObject("foo"); // retrieve object labelled "foo"
 
if (obj) {
	// do stuff with the obj
}
Syntax 2: Location
var obj = getObject(7, 3); // retrieve structure/feature on tile 7,3
 
if (obj) {
	// do stuff with the obj
}
Syntax 3: Object IDs
var obj = getObject(DROID, me, 63); // retrieve my droid #63
 
if (obj) {
	// do stuff with the obj
}
Availability 3.2+

Requires:

  • Warzone 3.2 and above

See "Notes" section for details of earlier incarnations of this function.

Contents

Jump to:

Algorithmic Complexity

Syntax 1: Labels:

  • O(log n) – Fast

Syntax 2: Location:

  • O(1) – Very fast

Syntax 3: Object IDs:

  • O(n) – Slow

See also

Related articles:

Â