Jump to content
Blitzen88

How to simultaneously check 2 arrays via foreach..?

Recommended Posts

 

Im trying to figure out how I can utilize foreach on two different arrays at the same time while filtering the results.

 

I'm trying to apply the targetKnowledge command to all enemy and friendly units:

 

Quote

_EnemyUnits = allUnits select { playerside getFriend side _x <= 0.6};

 

_FriendlyUnits = allUnits select  {side _x isEqualto playerside};

 

{

 

_KnowledgeArray = _x targetKnowledge _EnemyUnits // Here is my issue. I need to check all friendly units against all enemy units

 

//Filter Enemy units that meet certain criteria:

 

_KnownbyGroup = _KnowledgeArray select 0;

                  

_KnownbyUnit = _KnowledgeArray select 1;

                  

_LastSeen = _KnowledgeArray select 2;

 

if (_KnownbyGroup || _KnownbyUnit && _LastSeen < 30) then {

                  

_x (ie enemy unit) pushback _KnownEnemyUnits


};

 

}foreach _Friendly Un

Share this post


Link to post
Share on other sites

You need to use nested loops:

{
    _FriendlyUnit = _x;

    {
        _KnowledgeArray = _FriendlyUnit targetKnowledge _x;

        ...
    } forEach _EnemyUnits;

    ...
} forEach _FriendlyUnits;

 

  • Thanks 1

Share this post


Link to post
Share on other sites
17 hours ago, Schatten said:

You need to use nested loops:


{
    _FriendlyUnit = _x;

    {
        _KnowledgeArray = _FriendlyUnit targetKnowledge _x;

        ...
    } forEach _EnemyUnits;

    ...
} forEach _FriendlyUnits;

 

Would this stuff:

 

_KnownbyGroup = _KnowledgeArray select 0;

                  

_KnownbyUnit = _KnowledgeArray select 1;

                  

_LastSeen = _KnowledgeArray select 2;

 

Go before or after the targetknowledge command? I dint know which bracket/scope it goes in

Share this post


Link to post
Share on other sites

Since _KnowledgeArray is returned by targetKnowledge, its elements must obviously be accessed after this array is returned.

Share this post


Link to post
Share on other sites
15 minutes ago, Schatten said:

Since _KnowledgeArray is returned by targetKnowledge, its elements must obviously be accessed after this array is returned.

I guess, should it go after } foreach _EnemyUnits or before } foreach _FriendlyUnits?

Share this post


Link to post
Share on other sites

What is the purpose of your script and what is the ideal data format you'd like to return for that (an array of arrays, a long array of...)?

Share this post


Link to post
Share on other sites
14 hours ago, Blitzen88 said:

I guess, should it go after } foreach _EnemyUnits or before } foreach _FriendlyUnits?

Inside nested forEach, at the same scope.

Share this post


Link to post
Share on other sites
On 10/1/2024 at 1:32 AM, pierremgi said:

What is the purpose of your script and what is the ideal data format you'd like to return for that (an array of arrays, a long array of...)?

I was trying to “fix” the Marta Module by creating and removing groupicons based off of targetknowlegde. I think Marta uses Knowsabout. 

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

×