Jump to content

Donne

Member
  • Content Count

    4
  • Joined

  • Last visited

  • Medals

Posts posted by Donne


  1. Hello! I have some code here, that a community member helped me with, but I accidentally posted it in the Arma 3 editing section. I believe the Params command doesn't work in Arma 2(?) Can someone show me how the script below should look in Arma 2? Thank you ever so :)

     

     private _fnc_getrandindexes = {
     
    	params [ ["_array",[],[[]]], ["_indexcnt",1,[0]] ];
    	
    	if (_array isEqualTo []) exitWith {
    		//exit if passed _array is empty or not passed, if _indexcnt is not passed using 1
    		diag_log format ["_fnc_getrandindexes: Passed array is empty: %1 - exiting...",str _array]; 
    	};
    	
    	//define output
    	private _return_array = [];
    	
    	//some other prevents
    	if (_indexcnt isEqualTo 0) then {_indexcnt = 1};
    	if (_indexcnt > count _array) then {_indexcnt = count _array};
    	if (_indexcnt isEqualTo (count _array)) exitWith {
    		// exit with shuffled array if indexes count == _indexcnt
    		_return_array = _array call BIS_fnc_arrayShuffle;
    		_return_array
    	};
    	//loop
    	for "_i" from 1 to _indexcnt do {
    
    		private _randindex = selectRandom _array;
    		_return_array pushBack _randindex;
    		_array = _array - [_randindex];
    	};
    	//return
    	_return_array
    };
    
    
    _array = [variable_01, variable_02, variable_03, variable_04, variable_05];
    private _myrandomindxcnt = floor (random (count _array));
    private _mynewarray = [_array, _myrandomindxcnt] call _fnc_getrandindexes;
    //or if you want to change existing array
    _array = [_array, _myrandomindxcnt] call _fnc_getrandindexes;

     


  2. Thank you for the response!

     

    However, unless I'm being really silly and have misunderstood, I would like to pull a random number of variables from the array. Are the examples above only for a single variable?

     

    A bit like this, I guess:

     

    Random Number between 1-3 >>> that random number of variables chosen randomly from the array >>> returns a random number of random variables (so - maybe the random number would be two and we'd end up with variable_02 and variable_05, or something).


  3. Hello there. Sorry to hijack the thread, but I am also trying to get my head around a bit of randomness :icon_biggrin:

     

    So, take the following:

    _numberArray = [1, 2, 3];
    _number = _numberArray call BIS_fnc_selectRandom;

    How would one make the randomly generated number of selections from an array? For example, say our random number is 3.

    _array = [variable_01, variable_02, variable_03, variable_04, variable_05];

    How could we choose the random number (in this case, 3) from the above array?

     

    I'm sure the answer is pretty simple - probably involves the 'count' command - but just can't quite nail it.

×