I’d like to apologise for the lack of blog posts recently, be my guest and blame Putin for it. So today I’d like to show you something cool and very useful. What is really amazing about Arma is that an obvious solution could be lying in plain sight for ages yet be so hidden until one day it just presents itself.

Today I was playing with switch do case structure. I mostly neglected it because of the speed (if then is faster). Apparently if you finish case statement with ; ignoring usual block of code {}, if this case is matched, the script will drop to the next case containing block of code {} and execute that block. If there is no case with the block of code {} to follow, it will execute default block of code {}. If there isn’t default, nothing will happen, obviously.

testSwitch = { switch _this do { case "0"; case "2": {hint str ["2", _this]}; default {hint str ["default", _this]}; case "1"; }; }; "0" call testSwitch; //-> ["2", "0"] "1" call testSwitch; //-> ["default", "1"] "2" call testSwitch; //-> ["2", "2"] "3" call testSwitch; //-> ["default", "3"]

So what this has to do with KK_fnc_isEqual? As you already undoubtedly know, in Arma you cannot compare booleans and arrays with your usual == or != operators. If you try anything like true != false or [1,2,3] == [1,2,3] you will get an error. But hold on a second, switch do case on the other hand uses, and I think I won’t be wrong calling it, binary comparison. This is why it is case sensitive, means both variables have to be identical. In addition switch do case takes anything as argument (nil gets ignored), so you can compare anything to anything without getting errors like you do with == or !=.

Long story short, using switch do case you can compare booleans and arrays, and not just arrays, but multi-dimensional arrays! And all this time since Arma existence the solution was right there in plain view. I will be asking BIS people to include it in Arma 3 default functions. Or maybe it is better to ask to wrap it in a new command ANY isEqualTo ANY? Think it might be better. But for now, grab it here:

KK_fnc_isEqual = { switch (_this select 0) do { case (_this select 1) : {true}; default {false}; }; };

A few tests:

hint str (["hello", "Hello"] call KK_fnc_isEqual); //false hint str (["ABC", "ABC"] call KK_fnc_isEqual); //true hint str ([1, "ABC"] call KK_fnc_isEqual); //false (no error) hint str ([16, 16] call KK_fnc_isEqual); //true hint str ([player, vehicle player] call KK_fnc_isEqual); //true hint str ([false, false] call KK_fnc_isEqual); //true hint str ([true, false] call KK_fnc_isEqual); //false hint str ([true, 1 == 1] call KK_fnc_isEqual); //true hint str ([[1,2,3], [1,2,3]] call KK_fnc_isEqual); //true hint str ([[1,[2,[3]]], [1,[2,[3]]]] call KK_fnc_isEqual); //true hint str ([[1,[2,[3]]], [1,[2,[4]]]] call KK_fnc_isEqual); //false

Enjoy,
KK

EDIT: Victory!!! isEqualTo command is officially available on the DEV branch from today and soon will be heading to the main branch. If you need the same functionality for Arma 2, you can still use my function. I’d like to say big thanks to Jan Marecek a.k.a. japapatramtara for splendid work!

EDIT2: A bit late but still could have been another method of comparing arrays (Arma 3 only) if isEqualTo wasn’t added. Basically doing something like array1 in [array2] produces the same result and is as fast as isEqualTo:

_array1 = [1,[2,[3]]]; _array2 = [1,[2,[3]]]; _array1 in [_array2]; //true