Jump to content

Ilias38rus

{Executing} foreach allunits;

Recommended Posts

Question is: if im executing some code like:

_ea = [];

//1-st round
//unit 1 
//case 1
execVM ""; -> _ea = [1];
//unit 2
_ea = ["2"]

//2-nd round
//unit 1
//case 2
hint = str (_ea); //will be 2?
//unit 2

If yes, how is that possible to store some values for each _x in looped {} foreach allunits;?

Share this post


Link to post
Share on other sites

Your're going to need to expand here, I may be a little tired, but I have no clue what your're trying to accomplish...

 

Maybe something like:

_ea = [];

{
    _ea pushBack (name _x);
} forEacch allUnits;
  • Like 1

Share this post


Link to post
Share on other sites

To make an array, you need to change the case 1 to:

_ea = _ea + "1";
And for unit 2:

_ea = _ea + "2";
Now test your hint.

Share this post


Link to post
Share on other sites

All i'm asking about is: how to make some value storing for unit personal, added in foreach and which can be used in same function on next loop, for the unit, every unit own stored value

Share this post


Link to post
Share on other sites

So you want to filter through all units, and for each unit you want to store some data from that unit, or do you want to have each unit maintain a piece of data?

Share this post


Link to post
Share on other sites
  On 9/14/2015 at 1:34 AM, jshock said:

So you want to filter through all units, and for each unit you want to store some data from that unit, or do you want to have each unit maintain a piece of data?

while {true} do {   --|
{                     |
//unit 1 <--|         |
//case 1    |         |
//save 1    |         |
//unit 2 <--|         |
//save 2    |         |
} foreach allunits;   |
};                    |
                   <--|
//unit 1
//case 2
//load 1
//unit 2
//save 2

Share this post


Link to post
Share on other sites
_ea = [];
{
	_ea pushBack _forEachIndex;
} forEach allUnits;

That way, your _ea array will look like this: [0, 1, 2, 3, ...]. If you want it to start with 1, simply pushBack (_forEachIndex + 1).

But to be honest, I'm also not quiet sure what exacly you want.

Share this post


Link to post
Share on other sites

Holy crab, what's so difficult to understand, in foreach allunits executing for each unit, i need to store some data in the function for every unit personaly to have adility to use the data on next circle, if executing for unit 1 and srorring value 2, then executing for unit 2 and storring value 1, on next sircle start valye will be 1, but i do not need to retern it to standart, i need to get the stored value, according what unit is it!

Share this post


Link to post
Share on other sites

Something like...


storedUnits = [
    [  ],    //unit references
    [  ]    //unit data
];

while { true } do {
    {
        _unit = _x;
        _unitReferences = storedUnits select 0;
        _unitsData = storedUnits select 1;
        

        //Have we already stored this unit
        _found = _unitReferences find _unit;
        
        //If NOT, find returns -1 if not found
        if ( _found isEqualTo -1 ) then {

            //Add a refernce to the unit
            _index = _unitReferences pushBack _unit;

            //Get some info about the unit
            _data = uniformItems _unit;

            //Store the info in the data array at the same index as the unit reference
            _unitsData set [ _index, _data ];

        }else{
            //We have a reference already

            //Get stored data from same index as reference ( _found )
            _data = _unitsData select _found;

            //If the unit items in his uniform have changed
            if !( _data isEqualTo uniformItems _unit ) then {

                //Get list of items
                _data = uniformItems _unit;

                //Update stored data
                _unitsData set [ _found, _data ];

            };
        };

        sleep 1;

    }forEach allUnits; //Only returns alive and active units
};

OR


while { true } do {
    {
        _unit = _x;

        //Have we already stored data about this unit
        _found = _unit getVariable [ "data", -1 ];

        //If NOT, getvariable returns default value of -1
        if ( _found isEqualTo -1 ) then {

            //Get some info about the unit
            _data = uniformItems _unit;

            //Store the data on the unit in the variable "data"
            _unit setVariable [ "data", _data ];

        }else{
            //We have some data

            //If the unit items in his uniform have changed
            if !( _found isEqualTo uniformItems _unit ) then {

                //Get list of items
                _data = uniformItems _unit;

                //Update stored data
                _unit setVariable [ "data", _data ];
            };
        };

        sleep 1;

    }forEach allUnits; //Only returns alive and active units
};

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

×