Jump to content
Sign in to follow this  
snkman

Removing an Array from an Array.

Recommended Posts

I do work with a Global Variable, which is an Array:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

Group_Array = [];

If some conditions match, a script do add group/s to the "Group_Array" in a seperate array.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

Group_Array = Group_Array + [ [_groupA, _groupB, _groupC] ];

Now the "Group_Array" looks like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[ [EAST-1-A, EAST-1-B, EAST-1-C] ]

After some time some more group/s get added to the "Group_Array".

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

Group_Array = Group_Array + [ [_groupA, _groupB, _groupC] ];

Now the "Group_Array" looks like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[ [EAST-1-A, EAST-1-B, EAST-1-C], [EAST-1-D, EAST-1-E, EAST-1-F] ]

My question now is:

How can i remove the array, where the groups are stored in.

I mean [EAST-1-A, EAST-1-B, EAST-1-C] or [EAST-1-D, EAST-1-E, EAST-1-F] if some conditions match.

This is a "Group_Array" monitoring script, which do monitor the "Group_Array".

It's only for debug.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

while {True} do

{

    _group_array = Group_Array;

    sleep 1;

    if (count _group_array > 0) then

    {

         _count = 0;

         while {_count < count _group_array} do

         {

              _array = (_group_array select _count);

              _count = _count + 1;

              sleep 0.1;

              Group_Array = Group_Array - [_array];

         };

    };

};

With this monitoring script the arrays [EAST-1-A, EAST-1-B, EAST-1-C] and [EAST-1-D, EAST-1-E, EAST-1-F] should be removed after another from the "Group_Array"

After the first loop the "Group_Array" should look like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[ [EAST-1-D, EAST-1-E, EAST-1-F] ]

After the second loop the "Group_Array" should look like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[]

But this simply didn't work...

Isn't it possible, to remove a array from a array?

Share this post


Link to post
Share on other sites

Try something like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_groupIndexToDelete = x;

Group_Array set [_groupIndexToDelete, "DELETE"];

Group_Array - ["DELETE"];

x need to be the index of course.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

while {True} do

{

   _group_array = Group_Array;

   sleep 1;

   if (count _group_array > 0) then

   {

        _count = 0;

        while {_count < count _group_array} do

        {

             _array = (_group_array select _count);

             // do whatever you want with the array

             // then change the content of _array to "##S_REMOVE_ME_S##"

             _group_array set [_count, "##S_REMOVE_ME_S##"];

             _count = _count + 1;

             sleep 0.1;

             Group_Array = Group_Array - ["##S_REMOVE_ME_S##"];

        };

   };

};

Whatever you choose for "##S_REMOVE_ME_S##", it's up to you.

T_D was faster wink_o.gif

Xeno

Share this post


Link to post
Share on other sites

lol damn it works!

I was trying to find a way for more then 15 hours. whistle.gif

Thank you very much for showing me the correct way T_D and _Xeno_

Now i finally can continue work. smile_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×