scottb613 285 Posted September 12, 2022 Hi Folks, Working on a simple script where I want to redistribute remaining mags among team members - after a firefight - as I would expect would happen in real life. I plan to count all the primary weapon magazines and distribute the remaining evenly among respective weapon users. I haven't figured out how to handle a unit that may have different types of magazines for their primary weapon - yet. It's been a while since I've done any heavy Arma scripts. What am I doing wrong? I simply want to count the remaining mags of the primary weapon. The string comparison never increments the counter. I tried making both a STR. I looked at each value and the array element includes brackets and quotes which is probably the cause. _priWeap = primaryWeapon player; _priMag = primaryWeaponMagazine player; _magsArr = magazines player; _cntMags = count _magsArr; _logger = format ["%1 Mags",_cntMags]; //hint _logger; _cnt1 = 0; { if (_x == _priMag) then { _cnt1 = _cnt1 + 1; }; } forEach _magsArr; _logger = format ["%1 Mags",_cnt1]; hint _logger; Thanks. Regards, Scott Share this post Link to post Share on other sites
sarogahtyp 1109 Posted September 12, 2022 in your code you cycle through the array of strings _magsArr using a forEach loop which gives you the current string in _x. But you are comparing _x wich is a string with the array of strings _priMag. Thats the problem, primaryWeaponMagazine returns an array of strings but not a single string. Edit: you could use: _x in _priMag https://community.bistudio.com/wiki/in 1 Share this post Link to post Share on other sites
scottb613 285 Posted September 12, 2022 On 9/12/2022 at 11:27 AM, sarogahtyp said: in your code you cycle through the array of strings _magsArr using a forEach loop which gives you the current string in _x. But you are comparing _x wich is a string with the array of strings _priMag. Thats the problem, primaryWeaponMagazine returns an array of strings but not a single string. Edit: you could use: _x in _priMag https://community.bistudio.com/wiki/in Thanks for the explanation - let me give that a try. It's amazing how much time you can spend attempting to overcome a simple hurdle. Regards, Scott Share this post Link to post Share on other sites
pierremgi 4930 Posted September 12, 2022 This could help: compatibleMagazines 2 Share this post Link to post Share on other sites
scottb613 285 Posted September 14, 2022 On 9/12/2022 at 5:39 PM, pierremgi said: This could help: compatibleMagazines Hi Pierre, EXCELLENT - that was the piece of the puzzle that had me stalled on completing this script - I didn't know how to find the respective magazines for each weapon. Thanks! Regards, Scott Share this post Link to post Share on other sites