Yay! Thank you, André, thank you very much for your donation and support! This is what André wrote:

from Nokman for the real_time and more thx

Ok, will tell you this, I’m currently working on yet another extension, pretty useful one too… But enough for now, back to the tutorial :)

So, something wonderful has happened… There have been some changes in the way arrays are handled. I’m currently waiting for official confirmation that arrays have indeed received some love from BIS programmers. In the mean time I revisited my earlier tutorials on arrays and then tested it in Arma 2 to make sure no mistake was made then. The earlier tuts are still valid for Arma 2. Dev branch of Arma 3 however has new handling, hopefully soon to be transferred to the main branch.

The changes affect in, find and - commands. In short, you can now use these commands with multidimensional arrays (arrays inside arrays). Let me demonstrate this on a few examples:

1 in [1,[2,[3]],[[[4]]]] //Arma 2 => true //Arma 3 => true [2,[3]] in [1,[2,[3]],[[[4]]]] //Arma 2 => false //Arma 3 => true [[[4]]] in [1,[2,[3]],[[[4]]]] //Arma 2 => false //Arma 3 => true

As you can see in command will now treat array in array just like another element of the base array. Base array: [element1, element2, element3...] where any element could be an additional array construct, [1,[2,[3],4]] for example. The same applies to find command:

[1,[2,[3]],[[[4]]]] find 1 //Arma 2 => 0 //Arma 3 => 0 [1,[2,[3]],[[[4]]]] find [2,[3]] //Arma 2 => -1 //Arma 3 => 1 [1,[2,[3]],[[[4]]]] find [[[4]]] //Arma 2 => -1 //Arma 3 => 2

But I personally think the best use of the enhanced functionality is that you can now remove elements of multidimensional arrays with more ease:

[1,[2,[3]],[[[4]]]] - [1] //Arma 2 => [[2,[3]],[[[4]]]] //Arma 3 => [[2,[3]],[[[4]]]] [1,[2,[3]],[[[4]]]] - [[2,[3]]] //Arma 2 => [1,[2,[3]],[[[4]]]] //Arma 3 => [1,[[[4]]]] [1,[2,[3]],[[[4]]]] - [[[[4]]]] //Arma 2 => [1,[2,[3]],[[[4]]]] //Arma 3 => [1,[2,[3]]]

Note that in order to remove an element you have to define it from the base line: [[[[4]]]] in the above example, not 4, [4], [[4]] or [[[4]]]. And since this post is rather short, I’m going to top it up by sharing my version of arrayShuffle function (See EDIT2 at the bottom for the faster version):

KK_fnc_arrayShuffle = { private ["_cnt","_el1","_indx","_el2"]; _cnt = count _this - 1; _el1 = _this select _cnt; _this resize _cnt; for "_i" from 0 to _cnt + random 1 do { _indx = floor random _cnt; _el2 = _this select _indx; _this set [_indx, _el1]; _el1 = _el2; }; _this set [_cnt, _el1]; _this };

KK_fnc_arrayShuffle is almost 4 times faster than BIS_fnc_arrayShuffle when compared on just 10 elements array. Also, it actually modifies the original array, just like PHP’s shuffle(). In addition I made it also return the array to make it behave like BIS function. Usage:

_arr = [0,1,2,3,4,5,6,7,8,9]; // method 1 _arr call KK_fnc_arrayShuffle; hint str _arr; // method 2 hint str (_arr call KK_fnc_arrayShuffle);

And why not to make it even better by adding another param to the function to have control over the strength of shuffling? Because of how KK_fnc_arrayShuffle works, it is quite easy to expand its functionality: (See EDIT2 at the bottom for the faster version)

KK_fnc_arrayShufflePlus = { private ["_arr","_cnt","_el1","_indx","_el2"]; _arr = _this select 0; _cnt = count _arr - 1; _el1 = _arr select _cnt; _arr resize _cnt; for "_i" from 1 to (_this select 1) do { _indx = floor random _cnt; _el2 = _arr select _indx; _arr set [_indx, _el1]; _el1 = _el2; }; _arr set [_cnt, _el1]; _arr };

The the number of default shuffling iterations is equal to the length of array, this is how it is in BIS function. With KK_fnc_arrayShufflePlus you can make a stronger or weaker shuffle if you want by passing second argument with desired number of iterations. Usage:

_arr = [0,1,2,3,4,5,6,7,8,9]; hint str ([_arr, 100] call KK_fnc_arrayShufflePlus);

Enjoy,
KK

EDIT: KK_fnc_arrayShuffle updated, thanks to Master85 for pointing out hidden flaw. Fixed. Also here is even faster function based on Fisher-Yates algorithm:

KK_fnc_arrayShuffleFY = { private ["_el","_rnd"]; for "_i" from count _this - 1 to 0 step -1 do { _el = _this select _i; _rnd = floor random (_i + 1); _this set [_i, _this select _rnd]; _this set [_rnd, _el]; }; _this };

EDIT2: Thought I’d revisit the shuffle function because of the new commands added to Arma 3, mainly pushBack and deleteAt. After testing new algorithm based on these new commands, I can tell you that it is 2.5 times faster than Fisher-Yates algorithm. Therefore I’m going to rewrite both shuffle functions, normal and plus, but will leave the old ones as an example of how not to code :) .

KK_fnc_arrayShuffle = { private "_cnt"; _cnt = count _this; for "_i" from 1 to _cnt do { _this pushBack (_this deleteAt floor random _cnt); }; _this }; _arr = [0,1,2,3,4,5,6,7,8,9]; hint str (_arr call KK_fnc_arrayShuffle);
KK_fnc_arrayShufflePlus = { private ["_arr","_cnt"]; _arr = _this select 0; _cnt = count _arr; for "_i" from 1 to (_this select 1) do { _arr pushBack (_arr deleteAt floor random _cnt); }; _arr }; _arr = [0,1,2,3,4,5,6,7,8,9]; hint str ([_arr, 100] call KK_fnc_arrayShufflePlus);