Versions Compared

Key

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

Three ways to retrieve an a specific object...

 

Syntax

Code Block
themeRDark
languagejavascript
titleThis function has 3 syntax options...
linenumberstrue
// 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
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

Code Block
themeRDark
languagejavascript
titleSyntax 1: Label
linenumberstrue
var obj = getObject("foo"); // retrieve object labelled "foo"
 
if (obj) {
	// do stuff with the obj
}
Code Block
themeRDark
languagejavascript
titleSyntax 2: Location
linenumberstrue
var obj = getObject(7, 3); // retrieve structure/feature on tile 7,3
 
if (obj) {
	// do stuff with the obj
}
Code Block
themeRDark
languagejavascript
titleSyntax 3: Object IDs
linenumberstrue
var obj = getObject(DROID, me, 63); // retrieve my droid #63
 
if (obj) {
	// do stuff with the obj
}
Div
classbox
Availability
Status
colourGreen
title3.2+

Requires:

  • Warzone 3.2 and above

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

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Algorithmic Complexity

Syntax 1: Labels:

  • O(log n) – Fast

Syntax 2: Location:

  • O(1) – Very fast

Syntax 3: Object IDs:

  • O(n) – Fast
Div
classbox

See also

Related articles: