Ilias38rus 5 Posted September 13, 2015 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
jshock 513 Posted September 14, 2015 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; 1 Share this post Link to post Share on other sites
Ranwer135 308 Posted September 14, 2015 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
Ilias38rus 5 Posted September 14, 2015 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
jshock 513 Posted September 14, 2015 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
Ilias38rus 5 Posted September 14, 2015 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
Heeeere's johnny! 51 Posted September 14, 2015 _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
Ilias38rus 5 Posted September 14, 2015 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
Greenfist 1863 Posted September 14, 2015 You can attach data to a particular unit with setVariable and read it with getVariable. Share this post Link to post Share on other sites
Ilias38rus 5 Posted September 14, 2015 On 9/14/2015 at 12:14 PM, Greenfist said: You can attach data to a particular unit with setVariable and read it with getVariable. Thanks, finaly, thanks Share this post Link to post Share on other sites
Larrow 2828 Posted September 14, 2015 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