Jump to content
  • 0

splitting nested arrays


Mr White

Question

Hello,

 

I am attempting to build a weapons/magazine list for AI. I'm using fnc_buildWeightedArray which right now is an agent of Satan in my eyes.

 

I can build two arrays:

_weapons = [["SCAR_L_STD_EGLM_RCO","30Rnd_556x45_Stanag"],["SCAR_H_CQC_CCO","20Rnd_762x51_B_SCAR"]];
_chance = [0.1,0.2];
_weightedArray = [_weapons,_chance] call fnc_buildWeightedArray;

no big deal, but when the array gets huge... it becomes pretty painful

 

What I'd really like to do is run a nested array, but I haven't had any luck splitting the data off.

_weaponsList = [
    [["SCAR_L_STD_EGLM_RCO","30Rnd_556x45_Stanag"],0.1],
    [["SCAR_H_CQC_CCO","20Rnd_762x51_B_SCAR"],0.2]
    ];
/*
Oh noes I am lost here
*/
_weightedArray = [_weapons,_chance] call fnc_buildWeightedArray;

I've tried quite a few things, this was the strongest lead I had. I do need the split weapons and chance further in the script.

_listCount = (count _weaponsList) -1;
_weapons = [];
_chance = [];
for "_x" from 0 to _listCount do
{
    _weapons = ((_weaponsList select _x) select 0) + _weapons;
    _chance = ((_weaponsList select _x) select 1) + _chance;
};

but, doesn't work... I'm hoping it is simple, and I am starting to wonder if it is treating my arrays as strings.

 

not a lot of examples of the weighted array out there. Can anyone throw me a bone?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

How about using forEach.

_weaponsList = [
    [["SCAR_L_STD_EGLM_RCO","30Rnd_556x45_Stanag"],0.1],
    [["SCAR_H_CQC_CCO","20Rnd_762x51_B_SCAR"],0.2]
];

_weapons = [];
_chance = [];
{
    _weapons = _weapons + [_x select 0];
    _chance = _chance + [_x select 1];
} forEach _weaponsList;

Although using count instead of forEach might be better choice in this case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...