In Part 1 we have mostly looked at how to retrieve information from arrays. In this part we are going to look at changing and manipulating array. But first let’s look at two more array related commands you will need when dealing with class config entries, getArray and isArray. getArray will force output in the correct type (array) but will not convert it. For example if you have config entry as a string “sometextstring”, getArray will return [] and not [“sometextstring”]. isArray will simply tell you if the config entry is array or not.

class MakarovSD: Makarov {
  descriptionshort = "Silenced semi-automatic pistol <br/>Caliber: 9x18mm";
  displayname = "Makarov SD";
  magazines[] = {"8Rnd_9x18_MakarovSD", "8Rnd_9x18_Makarov"};
  ...
};
_result = isArray (configFile >> "cfgWeapons" >> "MakarovSD" >> "magazines"); //_result is true _result = getArray (configFile >> "cfgWeapons" >> "MakarovSD" >> "magazines"); //_result is ["8Rnd_9x18_MakarovSD","8Rnd_9x18_Makarov"] _result = getText (configFile >> "cfgWeapons" >> "MakarovSD" >> "magazines"); //_result is "" _result = isArray (configFile >> "cfgWeapons" >> "MakarovSD" >> "displayname"); //_result is false _result = getArray (configFile >> "cfgWeapons" >> "MakarovSD" >> "displayname"); //_result is [] _result = getText (configFile >> "cfgWeapons" >> "MakarovSD" >> "displayname"); //_result is "Makarov SD"

To change the value of array element use set command. This command takes array of arguments [index, newvalue]. set will also resize array if you change value of element beyond the length of array. You can also resize an array directly with resize command. resize will either truncate or extend the array depending on the length argument you supply.

_array = [1,2,3,4,6,6,7,8,9]; _array set [4,5]; //_array is now [1,2,3,4,5,6,7,8,9] _array set [count _array,10]; //_array is now [1,2,3,4,5,6,7,8,9,10] _array set [12,13]; //_array is now [1,2,3,4,5,6,7,8,9,10,<null>,<null>,13] _array resize 3; //_array is now [1,2,3] _array resize 5; //_array is now [1,2,3,<null>,<null>] _array resize 0; //_array is now []

You can undefine array element by assigning nil to it. This will neither erase the element  nor will it alter the length of the array.

_array = [1,2,3,4,5]; _array set [2,nil]; //_array is now [1,2,any,4,5]

There is no direct way of removing elements from array resulting in array length changes. However there are several workarounds based on another great feature of ArmA arrays. You can simply add and subtract arrays with + and operators. Addition will just do that add the 2nd array to the 1st array changing the 1st array length to accommodate new values.

_array = [4,5,6]; _array = _array + [7,8,9]; //_array is now [4,5,6,7,8,9] _array = [1,2,3] + _array; //_array is now [1,2,3,4,5,6,7,8,9]

Subtraction will remove ALL elements of the 2nd array from the 1st array changing the length of the 1st array.

_array = [1,1,2,2,3,3,4,4,5,5]; _array = _array - [1]; //_array is now [2,2,3,3,4,4,5,5] _array = _array - [4,2,5]; //_array is now [3,3]

If array element is array itself it cannot be subtracted.

_array = [[1,2],[3,4]]; _array = _array - [[1,2]]; //_array is still [[1,2],[3,4]]

So to remove a single element of array you need to first change it to some unique to this array value then subtract this value. Assigning and subtracting Null objects such as objNull, locationNull, grpNull, taskNullteamMemberNull, controlNull, displayNull works too.

_array = [1,2,3,4,5]; _array set [1,"deletethis"]; //_array is now [1,"deletethis",3,4,5] _array = _array - ["deletethis"]; //_array is now [1,3,4,5] _array = _array set [3,objNull]; //_array is now [1,3,4,<NULL-object>] _array = _array - [objNull]; //_array is now [1,3,4]

Here is a neat trick for you when you want to add an element to array but want to make sure its value stays unique and doesn’t repeat. You can check if match exists of course before adding new element, or you simply assume the value exists, subtract it first before adding it again. This will ensure it will not repeat within the array.

_array = [1,2,3,4,5]; _array = (_array - [6]) + [6]; //_array is now [1,2,3,4,5,6] _array = (_array - [6]) + [6]; //_array is still [1,2,3,4,5,6]

This is it for the Part 2. Part 3 will deal with some more advanced stuff.

Enjoy,
KK