Jump to content
Sign in to follow this  
hellfire257

Magazine Counter

Recommended Posts

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

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 by aeroson

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  

×