Groups - labels.ini vs. script ids

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Groups - labels.ini vs. script ids

Post by aubergine »

If I create a group in labels.ini, say group ID 5, that group will be available to all scripts.

Groups created at runtime are usually private to the script that creates them, how is the conflict between a shared labels.ini group #5 and a private script group #5 handled?

Example: What if a script then adds some droids to group 5? Does it get it's own group 5 created, meaning it can no longer access the labels.ini group of same number? Are the groups defined in labels.ini listed in groupSizes[] array?

P.S. Sorry for asking so many dumb questions :oops:
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Groups - labels.ini vs. script ids

Post by aubergine »

Also, is groupAddArea() still limited to droids owned by the calling script player?

BTW: I'm sure groupAddArea() used to filter out commanders and transports, but looking at the code that doesn't appear to be the case any more?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Groups - labels.ini vs. script ids

Post by Per »

Label created groups get negative group IDs, and therefore should not conflict with private script groups, which should be using positive integers. Label groups are copied into each instance, so adding and removing members of these groups is fine. You will find them in the groupSizes[] array (yes, even though they have negative indices! javascript is so flexible).

groupAddArea() is still limited to owned droids. For some reason I'm unsure of, the wzscript limitation against commanders and transports is not there.
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: Groups - labels.ini vs. script ids

Post by Duha »

Per wrote:You will find them in the groupSizes[] array (yes, even though they have negative indices! javascript is so flexible).
I hope no one will use for (var x; x<array.length; x++) or Array.map for this array.
http://addons.wz2100.net/ developer
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Groups - labels.ini vs. script ids

Post by aubergine »

If someone wanted to get all the group ids, including negative ones, the easiest way would be:

Code: Select all

var groupIDs = [];

Object.keys(groupSizes).forEach( function isGroup(key) {
  if (typeof key== "number") groupIDs.push(key);
} );
In any case, I think having label-based IDs being negative is a good idea, normally you will only want to access them via labels. It also means that groups from labels.ini don't start appearing in normal iterations of groupSizes array. So I think the way Per has implemented it works really well.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply