Jump to content
AlecW

Having trouble with a script to cycle through a weapon's compatible muzzles

Recommended Posts

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

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

  • Like 1

Share this post


Link to post
Share on other sites
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

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...

 

  • Like 1

Share this post


Link to post
Share on other sites
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:

ctovDe8.png

Share this post


Link to post
Share on other sites
36 minutes ago, AlecW said:

 

It still goes directly to the last index 😕

 

 

 

That code throws up this error:

ctovDe8.png

not my fault. you should check for invisible chars which u probably copied. this is a known forum bug

  • Like 1

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

×