AlecW 2 Posted May 21, 2019 As the title implies, I'm having some issues with a script of mine. It works if you hardcode the selections to the array index position, but I'm trying to make it into a cycle, so I don't have to have 7 different buttons for 7 different suppressors (such as the MX SW and MK200.) I've been trying to do it with a for loop, but it keeps getting stuck on index 0. Can anyone spot what I'm doing wrong/suggest a better alternative? _a = 0; _pWeap = currentWeapon player; _muzzleSlot = getArray (configFile / "CfgWeapons" >> _pWeap >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems"); _muzzAmount = count _muzzleSlot; for [{private _a = 0}, {_a < _muzzAmount},{_a = _a + 1}] do { _pSupp = _muzzleSlot select _a; player addWeaponItem [_pWeap, _pSupp]; }; For some reason, it either gets stuck on index 0 or _muzzAmount (this happens if I remove "private" from line 4). Share this post Link to post Share on other sites
sarogahtyp 1105 Posted May 21, 2019 pls don't do multiple posts with same content. maybe you want delete this cause u opened an own thread for it now... Share this post Link to post Share on other sites
AlecW 2 Posted May 21, 2019 Just now, sarogahtyp said: pls don't do multiple posts with same content. maybe you want delete this cause u opened an own thread for it now... Yeah my bad, I realized after posting that the thread was inactive 1 Share this post Link to post Share on other sites
Vandeanson 1676 Posted May 21, 2019 31 minutes ago, AlecW said: _a = 0; Set this first line to private instead of further down, so the content of _a is recognized throughout the script. That might help later on:) Share this post Link to post Share on other sites
sarogahtyp 1105 Posted May 21, 2019 no for loop needed: _pWeap = currentWeapon player; _muzzleSlot = getArray (configFile / "CfgWeapons" >> _pWeap >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems"); { player addWeaponItem [_pWeap, _x]; } count _muzzleSlot; this code should do the same as yours above but without a for loop. but I don't get what u r aiming for... 1 Share this post Link to post Share on other sites
AlecW 2 Posted May 21, 2019 7 hours ago, Vandeanson said: Set this first line to private instead of further down, so the content of _a is recognized throughout the script. That might help later on:) It still goes directly to the last index 😕 5 hours ago, sarogahtyp said: no for loop needed: _pWeap = currentWeapon player; _muzzleSlot = getArray (configFile / "CfgWeapons" >> _pWeap >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems"); { player addWeaponItem [_pWeap, _x] } count _muzzleSlot; this code should do the same as yours above but without a for loop. but I don't get what u r aiming for... That code throws up this error: Share this post Link to post Share on other sites
sarogahtyp 1105 Posted May 21, 2019 36 minutes ago, AlecW said: It still goes directly to the last index 😕 That code throws up this error: not my fault. you should check for invisible chars which u probably copied. this is a known forum bug 1 Share this post Link to post Share on other sites