Looks like it is “array overload day” today, so might as well share this useful function based on KK_fnc_assocArrayXXXX functions, which I have edited a little bit and added KK_fnc_assocArrayAllKeys, which is ultimately more useful function than KK_fnc_assocArraySize, which I removed.
This function is designed to count unique keys every time you call it. It also returns current count for the key as it is counted, that is if you need immediate feedback. I personally used associative arrays for this purpose in other languages many many times and the lack of associative array handling in Arma is limiting. As an example I will demonstrate how easy it is to keep track of how many of which ammo was fired by the player. Make sure you have KK_fnc_assocArrayXXXX function initialised, as KK_fnc_countUnique is based on them.
So instead of creating a random associative array, I will name one so that I can refer to it easily when needed. Let’s call it “AmmoStats”. This will be the reference string. The best way to keep record of the fired ammo is of course from the “Fired” Event Handler:
This will create and add fired ammo to stats in the array reference by “AmmoStats”. I also want to be able to see the stats with a scroll of a mouse. I need some kind of routine that will go through every key of the associative array (every type of ammo fired) and list corresponding value stored in the array:
And this is the result: