Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
An array of group sizes... |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// size of a group var size = groupSizes[groupID]<id>]; // will throw error if element missing // next available group ID var numGroups = groupSizes.length; |
Properties
Property | Type | Mandatory | Description | Game version |
---|---|---|---|---|
groupID<id> | Number | The ID of the droid group. This ID is generated when you create a new group using newGroup()Specify the group ID that you want to query the size of (see "Notes" below for important information). | 3.2 | |
length | Number | Returns the next available group ID, which can be used to create a completely new group. | 3.2 |
Return values
Value |
---|
Notes
See important notes regarding changes to groups in Warzone 3.2.
The groupSizesType | Notes | Game version | |
---|---|---|---|
<size> | Number | If the group <id> has been used, it's current size is returned as an integer that is ≥ 0. | 3.2 |
undefined | Undefined | The array element exists, but that group has never been used. | 3.2 |
<error> | ReferenceError | The array element does not exist and therefore it's value cannot be referenced. | 3.2 |
Notes
The groupSizes[] global is a "sparse" array – that means there might be gaps in the numbering of it's elements, which means that groupSizes.length
is not representative of the number of groups you've actually used.
All elements . As such, itup to groupSizes.length - 1
will be defined, but only groups that have been used will have a numeric value (the others will have a value of undefined
).
It's recommended to use the forEach() method when iterating the array (see example below).
Example
The .forEach() method simplifies iteration of sparse arrays – it will skip any undefined
elements...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
groupSizes.forEach( function get(groupSize, groupID) { // do stuff groupID has been used, so groupSize will always be ≥ 0 // any unused groups will be skipped } ); |
When you need a new group, you can either use newGroup() or simply add stuff to a group that doesn't yet exist:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// add a structure to a new group var newGroup = groupSizes.length; groupSizes[newGroup]; // ReferenceError groupAdd(newGroup, someStructure); |
class | suggest box |
---|
groupSizes[newGroup]; // 1
groupSizes.length; // == newGroup + 1 |
If you want to find the next free group that's already defined, you can do something like this (not recommended):
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var
i = 0,
nextUnused = groupSizes.length;
while (i < nextUnused) {
(typeof groupSizes[i] != "number") ? nextUnused = i : ++i;
}
// 'nextUnused' now contains the numeric ID of the next unused group
groupAdd(nextUnused, someObject); // create group by adding someObject to it |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
Earlier versions:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
| ||||
Div | ||||
|
Include Page | ||||
---|---|---|---|---|
|