(info) Other great resources: Official JS API docs, Scripting Forum

Groups

Organise game objects in to groups for easier iteration...

 

What are groups?

Groups are collections of Game objects. There are several benefits to using groups instead of custom arrays:

  • Objects will be removed from groups automatically if they are destroyed or moved to another group
  • Groups allow rapid access to the objects within them via enumGroup(), whereas custom arrays would require lots of function calls
  • Groups persist the save/load cycle, whereas custom arrays would prove problematic
  • Map-placed objects can be grouped and exposed to scripts via Labels (retrieve a Group Object using getObject()).

Note: Groups in the scripting environment are not the same as groups that a human player can set, they do not have shortcut keys, etc.

Which objects can be grouped?

Warzone 3.1

(tick) Droid object

(error) Feature object

(error) Structure object

(error) Other player's objects

Warzone 3.2+

(tick) Droid object

(tick) Feature object

(tick) Structure object

(tick) Other players objects

All versions

(info) Droid objects have a .group property stating which group they are in

(info) An object can only be in one of your groups at a time

(info) There are no reachable limits on the number of groups or the number of items in a group

How do I create groups?

There are four ways to create groups:

  • Use a map editor, like FlaME, to group objects (the groups are stored in labels.ini)
  • Define them manually in the labels.ini file associated with a map
  • Use the newGroup() function to create a group at runtime
  • Put an object in a group that doesn't exist yet (requires Warzone 3.2 or above)

What happens if objects get destroyed or transferred?

If an object is destroyed or transferred to another player (either via Nexus Link or donateObject()) it will be removed from the group its in.

In both cases, eventGroupLoss() will be triggered.

In the case of a group object being destroyed, eventGroupLoss() will be triggered before eventDestroyed().

Are they private to my scripts?

Groups created by your script are private and only your script can see them.

Groups defined by a map (in labels.ini) are available to all players, however:

  • They are copied to each script environment (so each script has it's own private copy of the group)
  • Their group IDs are multiplied by -1 to avoid conflict with script-created groups.

This means that groups defined in labels.ini have negative indices in the groupSizes[] array – bear this in mind if you're iterating the array.

Are they persistent?

The groups and objects they contain will survive the save/load cycle.

When you start a new game, the original map-defined groups (in labels.ini) will be reinstated.

Availability 3.1+

Requires:

  • Warzone 3.1 or above
  • Lots of improvements in Warzone 3.2

In 3.1 RC3 and earlier, empty groups were automatically deleted (bug #3684).

Contents

Jump to:

Scripting: Groups

Related Objects:

 Create them:

  • newGroup() – create a new group
  • WZ 3.2+ – add to a group that doesn't exist yet
  • labels.ini – group map-placed objects

Add things to them:

Remove things from them:

  • Put them in some other group

Count objects in them:

List them:

Retrieve their objects:

Monitor them:

Remove them:

  • not currently possible