Jump to content
Sign in to follow this  
twisted

foreach on a multidimensional array? how?

Recommended Posts

Tricky question (or probably just tricky to me)

how do i reference a multidminsional array using Foreach?

for example, say i make an array thats [weaponname, amount]

_weaponArray = _weaponArray + [_tempWeap, 1 + floor (random 3)];

and then i want to use foreach to add that to an ammobox.

{

_ammoPackBox addWeaponCargoGlobal [_x];

} foreach _weaponArray;

how is it done? i cannot find any reference on how to do it? its importnat to be able to keep the information in an array format as i regulalry delete the ammobox based on user distance but want to keep the weapon and relevant count constant.

Share this post


Link to post
Share on other sites

I'm not in the editor, but....

for "_i" from 0 to (count _weaponArray) - 1 do

{

_weapon = _weaponArray (select _i (select 0));

_amount = _weaponArray (select _i (select 1));

_ammoPackBox addWeaponCargoGlobal [_weapon, _amount];

};

Share this post


Link to post
Share on other sites

Much easier actually:

{
_ammoPackBox addWeaponCargoGlobal _x;
} foreach _weaponArray;

Share this post


Link to post
Share on other sites
Much easier actually:

{
_ammoPackBox addWeaponCargoGlobal _x;
} foreach _weaponArray;

Totally true! Just removing the [] will do the trick!

Share this post


Link to post
Share on other sites

oh thats pretty sweet. thanks will use it

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  

×