Home   Help Search Login Register  

Author Topic: Splitting a group  (Read 1998 times)

0 Members and 1 Guest are viewing this topic.

Offline Sparticus76

  • Members
  • *
Splitting a group
« on: 08 Sep 2008, 05:28:56 »
New problem I just cannot work out  :dry:

I'm trying to get a group, take all the even numbered guys out (every second) and create another group with them.
With help using the search feature I wrote this snippet so far...

Code: [Select]
private ["_Ldrgrp","_grp","_Oddldr","_group","_numg","_v"];
_Ldrgrp = _this select 0;
_grp    = units _Ldrgrp;
_numg   = count _grp;
_Oddldr = [_grp select 1];
_Oddldr join grpnull;
for [{_v = 3}, {_v < _numg}, {_v = _v + 2}] do
{
    [_grp select _v] join group _Oddldr;
};
_groupevn = units group _Oddldr;
_groupevn
and here is the .rpt fault I'm getting...

Code: [Select]
Error in expression <v = _v + 2}] do
{
[_grp select _v] join group _Oddldr;
};
_groupevn = units grou>
  Error position: <group _Oddldr;
};
_groupevn = units grou>
  Error group: Type Array, expected Object
Error in expression <v = _v + 2}] do
{
[_grp select _v] join group _Oddldr;
};
_groupevn = units grou>
  Error position: <group _Oddldr;
};
_groupevn = units grou>
  Error Generic error in expression

I really dont know what it wants to be an object, it looks like an object to me!  ???

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Splitting a group
« Reply #1 on: 08 Sep 2008, 13:09:26 »
You could remove the syntax error by replacing:
Code: [Select]
_Oddldr = [_grp select 1];
_Oddldr join grpnull;
with:
Code: [Select]
_Oddldr = _grp select 1;
[_Oddldr] join grpnull;

The problem then is that your logic is flawed. You are altering the array while iterating through it, so you won't actually get the right people in the right groups. Your _numg will be constant, but the number and contents of people in the group will change, so this will lead to an out-of-bounds error. I'm also not sure why you return something called _groupevn, when it is actually the units in the odd group.
Code: (splitGroup.sqf) [Select]
private ["_Ldrgrp","_grp","_oddPeople","_Oddldr","_numg","_v"];
_Ldrgrp = _this select 0;
_grp    = units _Ldrgrp;
_numg   = count _grp;
_Oddldr = _grp select 1;

// People with odd indices.
_oddPeople = [];

// Just record who will be moved. Don't alter array during iteration.
for [{ _v = 1 }, {_v < _numg}, {_v = _v + 2}] do
{
_oddPeople = _oddPeople + [_grp select _v];
};

// Move everyone out at once.
_oddPeople join (createGroup (side _Oddldr));

// Return both new groups.
[_Ldrgrp, group _Oddldr];
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Sparticus76

  • Members
  • *
Re: Splitting a group
« Reply #2 on: 09 Sep 2008, 02:27:10 »
Spooner you are a God send! Thankyou muchly.  :clap: :D

Offline Sparticus76

  • Members
  • *
Re: Splitting a group
« Reply #3 on: 12 Sep 2008, 06:23:09 »
OK, so I split the group! However now....a bit later in the script, I want to split the members in the two groups down to individual groups. Here's the script I have called by the leader of one of the split groups.


Code: [Select]
private ["_Ldr","_grp","_numg","_v","_split_grp_pool","_man","_temp","_Iog0","_Iog1","_Iog2","_Iog3","_Iog4","_Iog5","_Iog6"];

_Ldr = _this select 0;
_grp    = units _Ldr;
_numg   = count _grp;
_split_grp_pool = [_Iog0,_Iog1,_Iog2,_Iog3,_Iog4,_Iog5,_Iog6];


// The loop used to pluck units out of _grp and put them into individual groups from the _split_grp_pool variable
for [{ _v = _numg - 1}, {_v >= _numg}, {_v = _v - 1}] do
{
    _temp = [_grp select _v];
    _temp join grpNull;
    _split_grp_pool select _v = group _man;
};
[_grp,_numg,_split_grp_pool select 2];


and here is the error...


Code: [Select]
Error in expression <join grpNull;
_split_grp_pool select _v = group _man;
};
[_grp,_numg,_split_grp_>
  Error position: <= group _man;
};
[_grp,_numg,_split_grp_>
  Error Missing ;

a missing ;?...beats me.


Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Splitting a group
« Reply #4 on: 12 Sep 2008, 10:40:27 »
You can't do this sort of thing:
Code: [Select]
_split_grp_pool select _v = group _man;
You should use the set command to set individual elements of an array:
Code: [Select]
_split_grp_pool set [_v, group _man];

However, I really don't understand why you are using _split_grp_pool at all. Just returning _grp gives all the info you need (since that is an array of the units, you can just ask each one what its group is to find that out). This is a much simpler algorithm, perhaps too simple to even bother using a function for:
Code: (splitGroupIntoIndividuals.sqf) [Select]
private ["_Ldr","_grp"];

_Ldr = _this select 0;
_grp = units _Ldr;

{
    [_x] join grpNull;
} forEach _grp;

_grp;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Sparticus76

  • Members
  • *
Re: Splitting a group
« Reply #5 on: 12 Sep 2008, 12:04:51 »
I wanted to give the units a "home" so that I could get them and join them back to the original group at a later stage. How can I do this by your method? How can I find them again? As I said, I'm pretty new at this kinda thing, need a fair bit of help in this department.

Edit: Disreguard, I can still get them through _grp, even though they're now in grpNull....I dont understand the logic behind that. Oh well, doesnt really matter, so long as they dont follow the leader now (which they dont) and I can still "get" them so I can move them as individuals (which I can). Thanks Spooner.
« Last Edit: 13 Sep 2008, 04:05:08 by Sparticus76 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Splitting a group
« Reply #6 on: 13 Sep 2008, 14:59:30 »
Telling people to join grpNull makes then leave their current group, create and join a new group. If you tell multiple people to join grpNull at the same time, then they'll all join the same brand new group. They won't be in grpNull, since in this case that is just an instruction for them to make a new group, rather than to join an existing one.

I think some of your confusion could stem from using misleading variable names:
Code: [Select]
_Ldrgrp => This is actually a "group" type, though it implies that it is the leader of a group, which would be a man object.
_ldr => as above.
_grp => This is actually an array of men, rather than a "group" type, so perhaps might be better called "_soldiers" or "_men".
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Splitting a group
« Reply #7 on: 13 Sep 2008, 19:14:52 »
...If you tell multiple people to join grpNull at the same time, then they'll all join the same brand new group....
Are you sure this is true? I think it more likely that each unit is its own group.
« Last Edit: 13 Sep 2008, 19:16:44 by Mr.Peanut »
urp!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Splitting a group
« Reply #8 on: 13 Sep 2008, 19:23:43 »
I tested it and that seems to be how it works:
Code: (split into new one-man groups) [Select]
{
    [_x] join grpNull;
} forEach _units;

Code: (Move everyone into a single new group together) [Select]
_units join grpNull;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Splitting a group
« Reply #9 on: 15 Sep 2008, 02:01:11 »
Weird :blink:
urp!

Offline Sparticus76

  • Members
  • *
Re: Splitting a group
« Reply #10 on: 17 Sep 2008, 09:58:11 »
Thankyou, I'm picking up what you're putting down.