fn_selectRandomWeighted -- Usage ?

fn_selectRandomWeighted -- Usage ?

« posted: Feb 21, 2015, 05:59 AM »
I'm trying for the life of me to sort this, but it is late and I'm too bleary eyed to figure it out at this point.  I'm trying to use the fn_selectRandomWeighted function to select a heli from a list.

Code: [Select]
_heliTypes =[
["B_Heli_Attack_01_F", .25],
["O_Heli_Attack_02_black_F", .25],
["B_Heli_Light_01_armed_F", 1],
["O_Heli_Light_02_F", 1],
["I_Heli_light_03_F", 1]
];

_vehicleClass =  _heliTypes call BIS_fnc_selectRandomWeighted;

Do I need to convert this to two arrays, one of classnames and one of weights.  Like:
Code: [Select]
helitypes = [[classnames],[weights]];

Thanks for the help, folks!
  • Offline AgentRev
  • Developer
  • Veteran
  • ******
  • Posts: 2652

Re: fn_selectRandomWeighted -- Usage ?

« Reply #1 posted: Feb 21, 2015, 08:14 PM »
Don't use BIS_fnc_selectRandomWeighted, it is inaccurate and full of shitty code. Use my fn_selectRandomWeighted instead.

The arguments are: [<values array>, <weights array>]

They are separated because I wanted to keep it in line with the behavior of the BIS function.

When your values are a bunch of strings, like for what you're trying to do, you can use generateMissionWeights to split the values and weights into separate arrays to be used by the weight function:

Code: [Select]
_vehicleClass = (_heliTypes call generateMissionWeights) call fn_selectRandomWeighted;

Re: fn_selectRandomWeighted -- Usage ?

« Reply #2 posted: Feb 22, 2015, 12:14 AM »
Thanks for the tip, Rev!  I originally went with the fn_selectRandomWeighted first, but figured I'd give the BIS function a shake to see if the results changed.  This morning I chased through and looked at the generateMissionWeights function and sorted out how it was working.

I hadn't thought to call one function within the call of another.  I was getting my mind bent by the results of the missionweights function and their names. 

Thanks again for the reply!