Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Excerpt

An array of group sizes...

 

).

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
// size of a group
var size = groupSizes[groupID]id]; // will throw error if element missing
 
// next available group ID
var numGroups = groupSizes.length;

Properties

PropertyTypeMandatoryDescriptionGame version
groupIDidNumber(tick)(error)

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
lengthNumber(error)

Returns the next available group ID, which can be used to create a completely new group.

3.2

Return values

ValueTypeNotes

See important notes regarding changes to groups in Warzone 3.2.

The groupSizes
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
undefinedUndefinedThe array element exists, but that group has never been used.3.2
<error>ReferenceErrorThe 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).

Note also that groups defined in labels.ini will have negative indices in the array (which I'm not sure if .forEach() will process?).

Example

The .forEach() method simplifies iteration of sparse arrays – it will skip any undefined elements...

Code Block
themeRDark
languagejavascript
titleIterating through the groupSizes array...
linenumberstrue
groupSizes.forEach( function get(groupSize, groupID) {
	// do stuffany unused groups will be skipped, so this
	// groupID has been used, and groupSize will be ≥ 0
} );

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
themeRDark
languagejavascript
titleFast way to find next free group...
linenumberstrue
// add a structure to a new group
var newGroup = groupSizes.length;
 
groupSizes[newGroup]; // ReferenceError - no such element
 
groupAdd(newGroup, someStructure);
 
groupSizes[newGroup]; // 1
 

 

Div
classsuggest box
For Warzone 3.1, use groupSize() function instead (it also works on WZ 3.2+

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
themeRDark
languagejavascript
titleSlower way to find next free group...
linenumberstrue
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
classbox
Availability
Status
colourYellow
title3.2+

Requires:

  • Warzone 3.2 and above.

Earlier versions:

See Also

Related articles:

  • groupSize() – get size of group (WZ 3.1+)
  • groupAddDroid() – add a single droid to a group
  • groupAddArea() – add all droids within a specific map area to a group
  • Groups – quick reference for groups
  • newGroup() – create a new group
    Div
    classbox
    Contents

    Jump to:

    Table of Contents
    maxLevel5

    Div
    classbox

    Include Page
    .jslinks-groups
    .jslinks-groups