Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Count the number of droids of a given type for a specific player. |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var numDroids = countDroid([droidType[, player]]); |
Parameters
Parameter | Type | Mandatory | Notes | Warzone Version | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
droidType | Constant | What sort of droid should be counted?
Note that other .droidType constants cannot currently be used and will throw an error if you try to use them. Default: DROID_ANY | 3.1.0 | |||||||||
player | Number Constant | Which player(s) should the droids be counted for? You can specify a specific player ID, or one of the following constants:
Default: me | 3.1.0 |
Return value
Value | Type | Notes | Warzone Version |
---|---|---|---|
<number> | Number | The number of droids of the specified type for the specified player(s). | 3.1.0 |
<error> | Error | An error occurred, most likely you used an unsupported droidType or the specified player does not exist. | 3.1.0 |
Example
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
myTruckCount = countDroid(DROID_CONSTRUCT); // much faster than: mySlowTruckCount = enumDroid(me, DROID_CONSTRUCT).length; |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// we can't count DROID_WEAPON so have to approximate... // start by getting count of all enemy droids var totalEnemies = countDroid(DROID_ANY, ENEMIES); // now remove trucks and commanders var approxWeapons = totalEnemies - countDroid(DROID_COMMAND, ENEMIES) - countDroid(DROID_CONSTRUCT, ENEMIES); // there may be some sensors/ECMs, transports and repair droids in there, // but not that many so the figure will be pretty accurate // if you need to make it more accurate... var actualWeapons = approxWeapons; // count weapons for each enemy playerData.forEach(function(player, id) { if (!allianceExistsBetween(me, id)) { // enemy actualWeapons -= enumDroid(id, DROID_ECM).length; actualWeapons -= enumDroid(id, DROID_REPAIR).length; actualWeapons -= enumDroid(id, DROID_SENSOR).length; actualWeapons -= enumDroid(id, DROID_SUPERTRANSPORTER).length; actualWeapons -= enumDroid(id, DROID_TRANSPORTER).length; } }); // ...but is the extra accuracy worth it? // alternatively, you could do this... var actualWeapons = 0; playerData.forEach(function(player, id) { if (!allianceExistsBetween(me, id)) { // enemy actualWeapons += enumDroid(id, DROID_WEAPON).length; actualWeapons += enumDroid(id, DROID_CYBORG).length; } }); // ...but in late game there will be so many weapon droids that doing it // this way will actually be slower than the more bloaty approach shown // earlier (there will be very few ecm/repair/sensor/transport droids...) |
Div | ||
---|---|---|
| ||
This function is significantly faster than using enumDroid() and inspecting the .length property of the returned array, because countDroid() is referencing an existing value within the game engine and just returning that value. |
Div | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||
---|---|---|
| ||
See alsoRelated articles:
|