Other great resources: Official JS API docs, Scripting Forum
getObject()
- Aubergine
Syntax
// 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
Syntax | Parameter | Type | Mandatory | Description | Game version |
---|---|---|---|---|---|
#1 | labelName | String | Retrieve the object associated with the label name. See Labels for more information. | 3.2 | |
#2 | x, y | Number | 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 | |
#3 | type | Constant | The type of object to retrieve: | 3.2 | |
#3 | player | Number | The player to which the object belongs. When retrieving feature objects, specify player as | 3.2 | |
#3 | id | Number | The object ID. | 3.2 |
Return value
Value | Type | Description | Game version |
---|---|---|---|
<object> | The object that was retrieved. You can determine what sort of object it is by inspecting its .type property. | 3.2 | |
undefined | Undefined | The label was not found (applies to Syntax #1). | 3.2 |
null | Null | No object was found. | 3.2 |
<error> | Error | Invalid 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: Label | Syntax 2: Location | Syntax 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
var obj = getObject("foo"); // retrieve object labelled "foo" if (obj) { // do stuff with the obj }
var obj = getObject(7, 3); // retrieve structure/feature on tile 7,3 if (obj) { // do stuff with the obj }
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:
- enumFeature() – get a list of feature objects
- enumDroid() – get a list of droid objects
- enumStruct() – get a list of structure objects