hellfire257 3 Posted August 23, 2013 private ["_magazineSnapshot","_magazineOutput"]; _magazineSnapshot = magazines player; _magazineOutput = []; { _magazine = _x; diag_log format ["Selecting %1",_magazine]; _magazineName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); _magazineCount = {_x == _magazine} count _magazineSnapshot; _magazineOutput = _magazineOutput + [[_magazineName,_magazineCount]]; for "_i" from 0 to _magazineCount do {_magazineSnapshot = _magazineSnapshot - [_magazine]}; diag_log format ["Snapshot changed to: %1",_magazineSnapshot]; } forEach _magazineSnapshot; hint format ["%1",_magazineOutput]; diag_log format ["%1",_magazineOutput]; Hey all, I'm having trouble with the above bit of code not updating the variable _magazineSnapshot correctly as elements are removed; the forEach isn't being affected by the change. Is this a problem with scope or simply down to my usage of forEach? H. Share this post Link to post Share on other sites
aeroson 8 Posted August 23, 2013 (edited) Yup looks like forEach creates its own copy of the array. Use this instead: .......... _magazinesDone = []; { _magazine = _x; if(!(_magazine in _magazinesDone)) then { _magazinesDone set[ count _magazinesDone, _magazine]; .......... }; } forEach _magazineSnapshot; Edited August 23, 2013 by aeroson Share this post Link to post Share on other sites